|
Creating new samples using std::vector |
Bronxz
Member #16,061
August 2015
|
Hi! I would like to create empty sounds using std::vector, but I don't know what to type in "al_create_sample" function in order to create an empty sound. For example, when I create empty bitmaps with std::vector I do it like that: std::vector < ALLEGRO_BITMAP* > empty_bitmap; [...] empty_bitmap.push_back(al_create_bitmap(0,0)); In documentation, al_create_sample function looks like that: al_create_sample(void *buf, unsigned int samples, what do I have to type in this function in order to create an empty sound? Please help. And sorry for my english |
torhu
Member #2,727
September 2002
|
I don't know, but why not just set the pointer to NULL instead? |
#00JMP00
Member #14,740
November 2012
|
I have some ideas to solve it. 1st. Create an empty sample, as you would do normal. Then you keep pushing this example into the vector. Sadly you can end up with having a vector filled with samples pointing all at the same memory :-) 2nd, somewhat more complicated solution. Find the header for the sample definition. There look at the copy constructor of sample. You will need the same information as the copy constructor, since you make a copy. 3rd solution. You create a proforma class with sample included. There you define you're on copy constructor. When doing this, surely new objects will be created. Once I had this problems with bitmaps in vectors... |
Peter Hull
Member #1,136
March 2001
|
torhu said: I don't know, but why not just set the pointer to NULL instead? This sounds most sensible to me - just make sure you don't pass a null pointer to al_play_sample If you absolutely have to have a non-NULL, but empty, sample, I think this will work: void* dummy = al_malloc(0); ALLEGRO_SAMPLE* samp = al_create_sample(dummy, 0, 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_1, true); so for you, you could call it as std::vector<ALLEGRO_SAMPLE*> samples; [ ... ] samples.push_back(al_create_sample(al_malloc(0), 0, 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_1, true));
|
Bronxz
Member #16,061
August 2015
|
Than you all for help Problem solved. |
|