Hi,
I am an absolute beginner in programming sound under Windows, and I will probably not have understood the documentation (which is otherwise well made) at some point.
I want to be able synthesize a sound in the program (PCM format) and send it to the speakers.
I wrote an little test program, it compiles (Visual C++ 2010 Express) and everything works up to “engine->play2D(snd);” no sound but the message “Could not create sound buffer”.
Anyone a clue ?
Many thanks and best regards,
Jean.
// Trying to play a sound that is generated in memory
include <stdio.h> include <irrKlang.h> include <conio.h> include <math.h>
using namespace irrklang;
pragma comment(lib, "irrKlang.lib") // link with irrKlang.dll
int main(int argc, const char** argv) { // data char buffer[16384]; int i; SAudioStreamFormat format;
// enumerate devices & ask user for a sound device irrklang::ISoundDeviceList* deviceList = createSoundDeviceList(); printf("Devices available:\n\n"); for (int i=0; i<deviceList->getDeviceCount(); ++i) printf("%d: %s\n", i, deviceList->getDeviceDescription(i)); printf("\nselect a device using the number:\n"); int deviceNumber = _getch() - '0'; // create device with the selected driver const char* deviceID = deviceList->getDeviceID(deviceNumber); ISoundEngine* engine = createIrrKlangDevice(irrklang::ESOD_AUTO_DETECT, irrklang::ESEO_DEFAULT_OPTIONS, deviceID); deviceList->drop(); // delete device list printf("\n\nBuild sound in memory\n"); for (i = 0; i < 16384; i++) { buffer[i] = char(100.0 * sin(0.19634 * (float)(i%16))); //printf("loop:%d\n", i); }
printf("Put sound into buffer\n"); format.ChannelCount = 1; format.SampleRate = 8000; format.SampleFormat = ESF_U8; ISoundSource* snd = engine->addSoundSourceFromPCMData(buffer, 16384, "sinuoid", format, true ); printf("Play sound from buffer\n"); engine->play2D(snd);
// end and clean up printf("\nPress 'q' to quit.\n"); while(_getch() != 'q'); engine->drop(); // delete engine return 0; }
|