playing with sounds... needs a lot of work
git-svn-id: svn://anubis/anaglym/trunk@278 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
6e502367bc
commit
908a860482
58
AV.cc
58
AV.cc
@ -114,15 +114,30 @@ void AV::stop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<AV::Sound> AV::createSound()
|
||||||
|
{
|
||||||
|
refptr<Sound> s = new Sound(*this);
|
||||||
|
#if 0
|
||||||
|
m_sounds.insert(s);
|
||||||
|
#endif
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AV::playSound(AV::Sound * s)
|
||||||
|
{
|
||||||
|
m_active_sounds.insert(s);
|
||||||
|
}
|
||||||
|
|
||||||
void AV::playCallback(Uint8 * stream, int len)
|
void AV::playCallback(Uint8 * stream, int len)
|
||||||
{
|
{
|
||||||
static int pos = 0;
|
for (std::set<Sound *>::const_iterator it = m_active_sounds.begin();
|
||||||
Sint16 * str = (Sint16 *) stream;
|
it != m_active_sounds.end();
|
||||||
for (int i = 0; i < len / 4; i++)
|
it++)
|
||||||
{
|
{
|
||||||
str[i*2] = (Sint16) (32000.0 * sin(pos * 440.0 / AV_SOUND_RATE * 2.0 * M_PI));
|
if ((*it)->decode(stream, len) == 0)
|
||||||
str[i*2+1] = 0;
|
{
|
||||||
pos++;
|
m_active_sounds.erase(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,3 +181,34 @@ bool AV::Sound::load(FileLoader & fileLoader, const FileLoader::Path & path)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AV::Sound::play()
|
||||||
|
{
|
||||||
|
if (m_ss != NULL)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
cerr << "play()" << endl;
|
||||||
|
Sound_Rewind(m_ss);
|
||||||
|
cerr << "end play()" << endl;
|
||||||
|
#endif
|
||||||
|
m_av.playSound(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AV::Sound::stop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AV::Sound::loop(int times)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int AV::Sound::decode(Uint8 * stream, int len)
|
||||||
|
{
|
||||||
|
/* TODO: fix for len != m_ss->buffer_size */
|
||||||
|
cerr << "AV::Sound::decode()" << endl;
|
||||||
|
Uint32 len_decoded = Sound_Decode(m_ss);
|
||||||
|
cerr << "AV::Sound::decode() len: " << len << ", len_decoded: " << len_decoded << endl;
|
||||||
|
memcpy(stream, m_ss->buffer, len_decoded);
|
||||||
|
return len_decoded;
|
||||||
|
}
|
||||||
|
18
AV.h
18
AV.h
@ -2,11 +2,14 @@
|
|||||||
#ifndef VIDEO_H
|
#ifndef VIDEO_H
|
||||||
#define VIDEO_H
|
#define VIDEO_H
|
||||||
|
|
||||||
#include "FileLoader/FileLoader.h"
|
|
||||||
#include "refptr/refptr.h"
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_sound.h>
|
#include <SDL_sound.h>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#include "FileLoader/FileLoader.h"
|
||||||
|
#include "refptr/refptr.h"
|
||||||
|
|
||||||
#define AV_SOUND_RATE 44100
|
#define AV_SOUND_RATE 44100
|
||||||
|
|
||||||
class AV
|
class AV
|
||||||
@ -19,6 +22,10 @@ class AV
|
|||||||
~Sound();
|
~Sound();
|
||||||
bool load(FileLoader & fileLoader,
|
bool load(FileLoader & fileLoader,
|
||||||
const FileLoader::Path & path);
|
const FileLoader::Path & path);
|
||||||
|
void play();
|
||||||
|
void stop();
|
||||||
|
void loop(int times);
|
||||||
|
int decode(Uint8 * stream, int len);
|
||||||
protected:
|
protected:
|
||||||
AV & m_av;
|
AV & m_av;
|
||||||
SDL_RWops * m_rwops;
|
SDL_RWops * m_rwops;
|
||||||
@ -53,7 +60,8 @@ class AV
|
|||||||
{
|
{
|
||||||
return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON;
|
return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON;
|
||||||
}
|
}
|
||||||
refptr<Sound> createSound() { return new Sound(*this); }
|
refptr<Sound> createSound();
|
||||||
|
void playSound(Sound * s);
|
||||||
|
|
||||||
friend void AV_sound_callback(void * userdata, Uint8 * stream, int len);
|
friend void AV_sound_callback(void * userdata, Uint8 * stream, int len);
|
||||||
|
|
||||||
@ -66,6 +74,10 @@ class AV
|
|||||||
int m_height;
|
int m_height;
|
||||||
SDL_Surface * m_surface;
|
SDL_Surface * m_surface;
|
||||||
bool m_fullscreen;
|
bool m_fullscreen;
|
||||||
|
#if 0
|
||||||
|
std::set< refptr<Sound> > m_sounds;
|
||||||
|
#endif
|
||||||
|
std::set< Sound * > m_active_sounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -571,6 +571,7 @@ int Engine::loadSound(const string & name)
|
|||||||
if (avs->load(*m_fileLoader, path))
|
if (avs->load(*m_fileLoader, path))
|
||||||
{
|
{
|
||||||
int id = addSound(avs);
|
int id = addSound(avs);
|
||||||
|
avs->play();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -38,6 +38,8 @@ function key_down_event(key)
|
|||||||
ag.registerEventHandler(mouse_moves, "mouse_motion")
|
ag.registerEventHandler(mouse_moves, "mouse_motion")
|
||||||
elseif (key == "n") then
|
elseif (key == "n") then
|
||||||
ag.clearEventHandler("mouse_motion")
|
ag.clearEventHandler("mouse_motion")
|
||||||
|
elseif (key == "s") then
|
||||||
|
ag.loadSound("iris.mp3")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user