al_create_sample create double lengthen sample
GullRaDriel

I may be wrong but I'm currently playing with ex_record and ex_record_name to make myself a little recorder.

When just copy pasting the pasta and expanding the examples max_seconds, I ended with file that are the double of the file I currently save.

I digged up in the A5 sources and found that it isn't using the ALLEGRO_AUDIO_DEPTH (INT16 or whatever) in the sample size allocation.

My application or the example or the al_create_sample is wrong, but I had to divide samples by two to have the right amount of bytes saved.

Does anyone have a light for me ?

Code:

#SelectExpand
1/* Recorder is created like that: */ 2 3 internals -> recorder = al_create_audio_recorder( 4 internals -> fragment / internals -> latency , /* 10 seconds buffer space */ 5 internals -> frequency * internals -> latency , /* configure the fragment size to give us the given 6 latency in seconds */ 7 internals -> frequency, /* samples per second (higher => better quality) */ 8 ALLEGRO_AUDIO_DEPTH_INT16, /* 2-byte sample size */ 9 ALLEGRO_CHANNEL_CONF_2 /* stereo */ 10 ); 11 12/* running values: 13refresh_rate: 60.000000 14frequency: 44100 15max_seconds: 300 16fragment: 10 17latency: 0.100000 18*/ 19 20/* I save the sample like in the examples */ 21 22nstrprintf( date_str , "./output/%d/%s/%s" , local_time -> tm_year + 1900 , time_split[ 4 ] , time_split[ 3 ] ); 23nstrprintf( command , "mkdir -p %s" , date_str -> data ); 24system( _nstr( command ) ); 25nstrcat_bytes( date_str , "/" ); 26nstrcat_bytes( date_str , qvstudio -> titles[ selected_title ] ); 27nstrcat_bytes( date_str , "_" ); 28nstrcat_bytes( date_str , time_split[ 2 ] ); 29nstrcat_bytes( date_str , "H" ); 30nstrcat_bytes( date_str , time_split[ 1 ] ); 31nstrcat_bytes( date_str , "M" ); 32nstrcat_bytes( date_str , time_split[ 0 ] ); 33nstrcat_bytes( date_str , "S" ); 34nstrcat_bytes( date_str , ".wav" ); 35/* finished recording, but haven't created the sample yet */ 36ALLEGRO_SAMPLE *spl = al_create_sample( qvstudio -> record_buffer , 37 ( qvstudio -> record_buffer_pos - qvstudio -> record_buffer ) / 2 , /* HERE NOTICE THE /2. WITHOUT IT I GOT 2x LENGTH ! */ 38 qvstudio -> frequency , 39 ALLEGRO_AUDIO_DEPTH_INT16 , ALLEGRO_CHANNEL_CONF_2 , false ); 40al_save_sample( _nstr( date_str ) , spl ); 41al_destroy_sample( spl ); 42qvstudio -> record_buffer_pos = qvstudio -> record_buffer ; 43 44 45/* qvstudio variable struct for type reference */ 46 47#define MIN_SAMPLE_VAL 0x8000 48#define MAX_SAMPLE_VAL 0x7fff 49 50/*! Quiniou Studio Config structure */ 51typedef struct QS_INTERNALS 52{ 53 /* DISPLAY */ 54 /*! path to ttf font file */ 55 const char *font_file_small , 56 /*! path to ttf font file */ 57 *font_file_regular , 58 /*! path to ttf font file */ 59 *font_file_huge , 60 /*! path to background picture */ 61 *background_file ; 62 63 /*! size for little text output */ 64 int font_size_small , 65 /*! size for normal text output */ 66 font_size_regular , 67 /*! size for huge text output */ 68 font_size_huge , 69 /*! Screen W size */ 70 w , 71 /*! Screen H size */ 72 h ; 73 /*! Internal loop freq */ 74 float refresh_rate ; 75 76 /*! The 3 loaded fonts with their respective sizes */ 77 ALLEGRO_FONT *font[ 3 ]; 78 /*! Acutal display */ 79 ALLEGRO_DISPLAY *display ; 80 /*! Event queue */ 81 ALLEGRO_EVENT_QUEUE *queue ; 82 /*! Timer */ 83 ALLEGRO_TIMER *timer ; 84 85 /*! RECORDER */ 86 ALLEGRO_AUDIO_RECORDER *recorder ; 87 /*! fragment from recorder */ 88 ALLEGRO_AUDIO_RECORDER_EVENT *record_event ; 89 /*! recording buffer , stores up to max_seconds of audio */ 90 int16_t *record_buffer, 91 /*! points to the current recorded position */ 92 *record_buffer_pos, 93 /*! points to the end of the buffer */ 94 *record_buffer_end; 95 /*! recording flag */ 96 int is_recording ; 97 /*! Recording frequancy (44100,48000,96000) */ 98 int frequency ; 99 /*! Maximum size of sample */ 100 int max_seconds ; 101 /*! recorder internal buffer */ 102 int fragment ; 103 /*! Latency */ 104 float latency , 105 /*! Computed volume for current input */ 106 gain ; 107 108 /*! Loaded title list */ 109 char *titles[ NB_MAX_TITLES + 1 ]; 110 /*! number of loaded titles */ 111 int nb_titles ; 112 113}

SiegeLord

What is the type of qvstudio->record_buffer?

GullRaDriel

It's an int16_t *. The structure of qvstudio is described in the latter part of the source.

EDIT:
I polished it a bit. It now uses float32 depth, but I still have to divide by two at the end if I don't wan't an add on of white of the same length .

Edgar Reynaldo

Not sure if this is the problem here, but are you accounting for stereo vs mono recording? If you're expecting mono and you're using a stereo buffer for recording that might explain your sample being twice as long as you expect it to be.

GullRaDriel

I'm recording in stereo. I think the error may be in my own code. I'll post the recording parts here later in the day, I'm currently at work.

Edgar Reynaldo

Bump for reply.

Thou shalt not lock open threads!

GullRaDriel

I'll post what I got today. I have some cosmetics to do before posting something.

Thread #616105. Printed from Allegro.cc