Welcome to %s forums

BrainModular Users Forum

Login Register

How to play a sound in a c++ module

Create your own modules in C++
Post Reply
pansoul
Member
Posts: 39
Contact:

Unread post by pansoul » 16 Jul 2009, 02:18

Hello
First thank you for the new sdk and the example it contains.
i have a question about playing a sample. i suppose that the way to do that is to write in the buffer. my problem i need a function to read a file at the byte level to feed the buffer and it seems that there is no such a function in windows.h. I belive that C++ programmers use library like libsoundfile or OpenAL, but what about the use of library in usine ?

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 16 Jul 2009, 09:42

Hi Pansoul,

Happy to see you are around the SDK ;)

Need some precisions about you'r question.

Do you want to play an external sound file (external from usine and loaded by code) ?

in this case, you effectively need to do it by yourself, as usine didn't expose this kind of functionality for now.

you can look at the stream C++ class, at binary section
or make it the C way with the FILE object and related functions.

Hope it help

PS : the wiki isn't updated for the new SDK version yet :/
but if you produce a nice simple example of loading external sound file, it should go in :)
Martin FLEURENT - Usine Developer - SDK maintainer

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 16 Jul 2009, 11:24

right martignasse,
and also, the next version of the SDK will include a complete library to manage audio files and much more.
we are working on!

pansoul
Member
Posts: 39
Contact:

Unread post by pansoul » 31 Jul 2009, 17:00

yes martignasse i try to read an external file load by code.
i load a wav 16 bits stereo file as a binary file and obtain list of char. i try to decode value i obtain ( from -128 to 127) using this format http://sub0.developpez.com/FormatWAV/FormatWAV.htm it works a little ( i mean not with all file)
so i don't know where is the problem (format file ? but all my files are 16 bits stereo) i transform the amplitude of sample into [-1; 1] interval to feed the buffer output using double precision variable. i suppose that it's the good way.
i will try others technics waiting for new sdk.
thanks

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 31 Jul 2009, 23:29

-128 to 127? It sounds that you're treating the file as 8-bit audio. In a 16 bit stereo file, every sample contains four bytes, two for left, two for right. I'm not quite sure about this, but if I've understood the little documentation I've checked on the net, uncompressed WAVs are "little-endian", that means that the least signicant byte comes before the most significant and with interleaved stereo the left side comes before the right.
Bjørn S

pansoul
Member
Posts: 39
Contact:

Unread post by pansoul » 01 Aug 2009, 13:49

I decompress each octet as a char so it's normal to have value with a range of 256. To have 65535 directly with binary i would probably have to use WORD variable but i didn't succed with this variable. so i suppose that taking the most significant byte and multiplying it by 256 and adding it to the least significant i can obtain value with 65535.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests