Extracting score informations in a played soundtrack
Posted: Fri Aug 02, 2013 2:22 pm
Hello,
I use soundtracked music.
The structure of those files (.xm, .mod, .it ...) is interesting for synchronizing events in a game.
That is, as it's basically a score interpreted with embedded sampled instruments, you can extract a lot of informations during the play.
(when you have access to the score)
I'd like to obtain real-time informations about notes currently played and instruments, and so on (effects applied , etc.)
With Lua API, for getting the position currently played on a source, you call:
Source:tell(optional unit)
It returns a number exprimed in the «unit» given as parameter while the call.
By default, «unit» is seconds.
I'd like to modify «tell» function member for tracked music, for getting more than the position in the stream.
«tell» is defined in the Lua wrapper : modules/audio/wrap_Source.cpp
Like this: { "tell", w_Source_tell }
Here is the matching function:
«tell» is of course defined in the class «Source»: modules/audio/Source.cpp
«tell» is a virtual function, not implemented in «Source» class:
virtual float tell(Unit unit) = 0;
We find the member's code in the implementation of the «Source» class ; in the audio external API (OpenAL):
Let's see the «Pool» class ...
And finally (in Source class again):
Huho we're too deep here. We're already playing a sound, and it's too late for getting meta-informations of the tracked music (that is, getting score position, notes played , instruments number in play, and so on).
If someone has an idea, it will be very welcome.
I use soundtracked music.
The structure of those files (.xm, .mod, .it ...) is interesting for synchronizing events in a game.
That is, as it's basically a score interpreted with embedded sampled instruments, you can extract a lot of informations during the play.
(when you have access to the score)
I'd like to obtain real-time informations about notes currently played and instruments, and so on (effects applied , etc.)
With Lua API, for getting the position currently played on a source, you call:
Source:tell(optional unit)
It returns a number exprimed in the «unit» given as parameter while the call.
By default, «unit» is seconds.
I'd like to modify «tell» function member for tracked music, for getting more than the position in the stream.
«tell» is defined in the Lua wrapper : modules/audio/wrap_Source.cpp
Like this: { "tell", w_Source_tell }
Here is the matching function:
Code: Select all
int w_Source_tell(lua_State *L)
{
Source *t = luax_checksource(L, 1);
const char *unit = luaL_optstring(L, 2, "seconds");
Source::Unit u;
t->getConstant(unit, u);
lua_pushnumber(L, t->tell(u));
return 1;
}
«tell» is a virtual function, not implemented in «Source» class:
virtual float tell(Unit unit) = 0;
We find the member's code in the implementation of the «Source» class ; in the audio external API (OpenAL):
Code: Select all
float Source::tell(Source::Unit unit)
{
return pool->tell(this, &unit);
}
Code: Select all
float Pool::tell(Source *source, void *unit)
{
thread::Lock lock(mutex);
return source->tellAtomic(unit);
}
Code: Select all
float Source::tellAtomic(void *unit) const
{
if (valid)
{
float offset;
switch (*((Source::Unit *) unit))
{
case Source::UNIT_SAMPLES:
alGetSourcef(source, AL_SAMPLE_OFFSET, &offset);
if (type == TYPE_STREAM) offset += offsetSamples;
break;
case Source::UNIT_SECONDS:
default:
alGetSourcef(source, AL_SAMPLE_OFFSET, &offset);
ALint buffer;
alGetSourcei(source, AL_BUFFER, &buffer);
int freq;
alGetBufferi(buffer, AL_FREQUENCY, &freq);
offset /= freq;
if (type == TYPE_STREAM) offset += offsetSeconds;
break;
}
return offset;
}
return 0.0f;
}
If someone has an idea, it will be very welcome.