Expose audio pitch support in Lime legacy (thanks @PaulGene)

This commit is contained in:
Joshua Granick
2015-01-06 15:17:56 -08:00
parent 86493339e8
commit ec2056842e
7 changed files with 43 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ namespace nme
virtual bool update() = 0;
virtual void setTransform(const SoundTransform &inTransform) = 0;
virtual void setPitch(const float &inFloat) = 0;
virtual double getPosition() = 0;
virtual double setPosition(const float &inFloat) = 0;
virtual double getLeft() = 0;

View File

@@ -40,6 +40,7 @@ public:
virtual double setPosition(const float &inFloat) = 0;
virtual void stop() = 0;
virtual void setTransform(const SoundTransform &inTransform) = 0;
virtual void setPitch(const float &inFloat) = 0;
virtual double getDataPosition() { return 0.0; }
virtual bool needsData() { return false; }

View File

@@ -367,6 +367,7 @@ DEFINE_LIME_PRIM_1(sound_channel_get_position);
DEFINE_LIME_PRIM_2(sound_channel_set_position);
DEFINE_LIME_PRIM_1(sound_channel_stop);
DEFINE_LIME_PRIM_2(sound_channel_set_transform);
DEFINE_LIME_PRIM_2(sound_channel_set_pitch);
DEFINE_LIME_PRIM_4(sound_channel_create);
DEFINE_LIME_PRIM_1(sound_channel_needs_data);
DEFINE_LIME_PRIM_2(sound_channel_add_data);

View File

@@ -4456,6 +4456,18 @@ value nme_sound_channel_set_transform(value inChannel, value inTransform)
}
DEFINE_PRIM(nme_sound_channel_set_transform,2);
value nme_sound_channel_set_pitch(value inChannel, value inFloat)
{
SoundChannel *channel;
if (AbstractToObject(inChannel,channel))
{
float pitch = val_number(inFloat);
channel->setPitch(pitch);
}
return alloc_null();
}
DEFINE_PRIM(nme_sound_channel_set_pitch,2);
value nme_sound_channel_create(value inSound, value inStart, value inLoops, value inTransform)
{
Sound *sound;

View File

@@ -236,6 +236,10 @@ namespace nme
}
[theActualPlayer setVolume: inTransform.volume];
}
void setPitch(const float &inFloat) {
LOG_SOUND("AVAudioPlayerChannel setPitch()");
[theActualPlayer setPitch: inFloat];
}
void stop()
{
LOG_SOUND("AVAudioPlayerChannel stop()");

View File

@@ -410,6 +410,19 @@ namespace nme
}
void OpenALChannel::setPitch(const float &inFloat)
{
if (mUseStream)
{
if (mStream) mStream->setPitch(inFloat);
}
else
{
alSourcef(mSourceID, AL_PITCH, inFloat);
}
}
void OpenALChannel::stop()
{
if (mUseStream)
@@ -1286,6 +1299,15 @@ namespace nme
}
void AudioStream_Ogg::setPitch(const float &inFloat)
{
if (!mSuspend)
{
alSourcef(source, AL_PITCH, inFloat);
}
}
void AudioStream_Ogg::suspend()
{
mSuspend = true;

View File

@@ -97,6 +97,7 @@ class OpenALChannel;
bool playing();
bool update();
void setTransform(const SoundTransform &inTransform);
void setPitch(const float &inFloat);
double getPosition();
double setPosition(const float &inFloat);
double getLeft();
@@ -202,6 +203,7 @@ class OpenALChannel;
double setPosition(const float &inFloat);
double getPosition();
void setTransform(const SoundTransform &inTransform);
void setPitch(const float &inFloat);
void stop();
void suspend();
void resume();