GP32 Array Of Sounds/samples ?


ConsoleTom

Member
Joined
Dec 4, 2003
Messages
106
Age
48
Location
Germany
Website
Visit site
Hi !

I would like to create an array that contains sounds. Now i have a Snaredrum-Sample in an Array

unsigned short SnareDrum[20000] = {x SampleData for 1 Snaredrum x};

then i would play it like this:

GpPcmPlay((unsigned short*)SnareDrum,sizeof(SnareDrum),0);

but what i need is an array - for example 5 x 20000.

The Play Routine should work like this

GpPcmPlay((unsigned short*)SnareDrum[2],sizeof(SnareDrum[2]),0);

How do i declare it ?

Greetings

Tobias
 
A fixed-size array for sounds is not a good idea, as your sounds won't all have the same length (a guess, but I think this is why the sizeof is there for).

Instead your should create a structure like this:
Code:
typedef struct {
unsigned short *sound;
int length;
} s_sound;

Then you would declare your array like this:
Code:
s_sound sound[5];

Then make these pointers point to your actual sounds, and set the good length for each sound.
Code:
sound[2].sound = SnareDrum;
sound[2].length = sizeof(SnareDrum);

To play your sound:
Code:
GpPcmPlay((unsigned short*)sound[2].sound,sound[2].length,0);

Note that you still need each sound array declaration (unsigned short SnareDrum[20000] = {x SampleData for 1 Snaredrum x}; ) but that way all your sounds can have different sizes.
 
Hi !

Thanks, that should help. I'll try it.

I thought about defining a struct. But the idea with the size-info is even better.

Greetings

Tobias
 
Back
Top