Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Using "addSoundSourceFromPCMData"

jeanrenier
Registered User
Quote
2012-11-01 17:22:56

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;
}



niko
Moderator
Quote
2012-11-02 21:02:23

Hm, just a guess, maybe you missed to set the FrameCount in the format structure?


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact