fixed some bugs in SoundStream

property style functions for SoundStream and SoundSource
fixed pong and soundstream samples: thx AndrejM!

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1552 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
Trass3r 2010-08-25 20:37:00 +00:00
parent dda69de7e9
commit 64b4bd8472
4 changed files with 79 additions and 70 deletions

View file

@ -29,28 +29,34 @@ class MySoundStream : SoundStream
// We create a sound buffer to load samples from files
m_buff = new SoundBuffer("Data/car_idle.wav");
m_data = m_buff.getSamples[0..m_buff.getSamplesCount];
m_data = m_buff.samples[0..m_buff.samplesCount];
}
protected:
/*
bool onStart()
{
// No specifics things to do, just return true.
return true;
}
bool onGetData(out short[] data)
*/
override bool onGetData(out short[] data)
{
// We ensure that we have enough data to send
if (m_cursor + this.getSampleRate > m_data.length)
if (m_cursor + this.sampleRate > m_data.length)
return false;
// Assign data in the buffer ...
data = m_data[m_cursor..m_cursor + this.getSampleRate];
data = m_data[m_cursor..m_cursor + this.sampleRate];
// ... and increment the cursor
m_cursor += this.getSampleRate;
m_cursor += this.sampleRate;
return true;
}
override void onSeek(float timeOffset)
{
}
}
void main()
@ -59,20 +65,20 @@ void main()
display("Playing sound !\n Press enter to stop playback.");
stream.play();
read();
read(); // prevent console from closing
stream.stop();
}
void display(char[] c)
void display(string c)
{
version (Tango)
{
{
Stdout(c).newline;
}
}
else
{
writefln("%s", c);
}
{
writeln(c);
}
}
/**
@ -81,11 +87,11 @@ void display(char[] c)
void read()
{
version (Tango)
{
{
Cin.get();
}
}
else
{
{
readln();
}
}
}
}