working on audio support
git-svn-id: svn://anubis/anaglym/trunk@257 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
d27f18b701
commit
6d924e73db
@ -888,6 +888,9 @@ void Engine::run()
|
||||
case SDLK_F5:
|
||||
reloadProgram();
|
||||
break;
|
||||
case SDLK_F6:
|
||||
SDL_PauseAudio(0);
|
||||
break;
|
||||
default:
|
||||
key_down_event(event.key.keysym.sym);
|
||||
}
|
||||
|
2
Makefile
2
Makefile
@ -28,7 +28,7 @@ FTGLINCLUDE := $(shell pkg-config --cflags ftgl)
|
||||
FTGLLIBS := $(shell pkg-config --libs ftgl)
|
||||
|
||||
SDLINCLUDE := $(shell sdl-config --cflags)
|
||||
SDLLIBS := $(shell sdl-config --libs) -lSDL_image
|
||||
SDLLIBS := $(shell sdl-config --libs) -lSDL_image -lSDL_sound
|
||||
|
||||
ODEINCLUDE := $(shell ode-config --cflags)
|
||||
ODELIBS := $(shell ode-config --libs)
|
||||
|
34
Video.cc
34
Video.cc
@ -4,8 +4,22 @@
|
||||
#include <GL/glu.h>
|
||||
#include <SDL.h>
|
||||
#include <iostream>
|
||||
#include <SDL_sound.h>
|
||||
#include <math.h>
|
||||
using namespace std;
|
||||
|
||||
static void Video_sound_callback(void * userdata, Uint8 * stream, int len)
|
||||
{
|
||||
static int pos = 0;
|
||||
Sint16 * str = (Sint16 *) stream;
|
||||
for (int i = 0; i < len / 4; i++)
|
||||
{
|
||||
str[i*2] = (Sint16) (32000.0 * sin(pos / 44100.0 * M_PI));
|
||||
str[i*2+1] = 0;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
Video::Video()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER))
|
||||
@ -30,6 +44,26 @@ Video::Video()
|
||||
m_surface = NULL;
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
|
||||
// Sound_Init();
|
||||
SDL_AudioSpec desired;
|
||||
desired.freq = 44100;
|
||||
desired.format = AUDIO_S16SYS;
|
||||
desired.channels = 2;
|
||||
desired.samples = 4096;
|
||||
desired.callback = Video_sound_callback;
|
||||
desired.userdata = this;
|
||||
if (SDL_OpenAudio(&desired, NULL) < 0)
|
||||
{
|
||||
cerr << "Sound_OpenAudio() error." << endl;
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
|
||||
Video::~Video()
|
||||
{
|
||||
Sound_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void Video::start(int width, int height, bool fullscreen, bool grab_input,
|
||||
|
Loading…
x
Reference in New Issue
Block a user