Tscope5
audio.c
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
20 
21 
22 
23 #include "../include/tscope5/audio.h"
24 #include "../include/tscope5/audio_internal.h"
25 #include "../include/tscope5/system_internal.h"
26 
27 
46 unsigned int ts5_set_audio_frequency(unsigned int frequency)
47 {
48  if (!_ts5_is_tscope5_installed) {
49  ts5_install_tscope5("ts5_set_audio_frequency");
50  }
51 
52  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_frequency(%u)\n", frequency);
53 
54  unsigned int retval = _ts5_status.audio_status.frequency;
55 
56  if (frequency!=TS5_11025 && frequency!=TS5_22050 && frequency!=TS5_44100) {
57  ts5_fatal("ts5_set_audio_frequency: unknonwn frequency requested\n");
58  }
59 
60  _ts5_status.audio_status.frequency = frequency;
61 
62  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_frequency: set sample rate to %u (was %u)\n",
63  _ts5_status.audio_status.frequency, retval);
64 
65  return retval;
66 }
67 
68 
75 {
76  ts5_check_audio("ts5_get_audio_frequency");
77  ts5_log(TS5_LOGLEVEL_4, "ts5_get_audio_frequency()\n");
78 
79  return al_get_voice_frequency(_ts5_status.audio_status.voice);
80 }
81 
82 
101 unsigned int ts5_set_audio_channels(unsigned int channels)
102 {
103  if (!_ts5_is_tscope5_installed) {
104  ts5_install_tscope5("ts5_set_audio_channels");
105  }
106 
107  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_channels(%d)\n", channels);
108 
109  unsigned int retval = _ts5_status.audio_status.channels;
110 
111  if (channels!=TS5_MONO && channels!=TS5_STEREO) {
112  ts5_fatal("ts5_set_audio_channels: unknonwn number of channels requested\n");
113  }
114 
115  _ts5_status.audio_status.channels = channels;
116 
117  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_channels: set number of channels to %u (was %u)\n",
118  _ts5_status.audio_status.channels, retval);
119 
120  return retval;
121 }
122 
123 
130 {
131  ts5_check_audio("ts5_get_audio_channels");
132  ts5_log(TS5_LOGLEVEL_4, "ts5_get_audio_channels()\n");
133 
134  ALLEGRO_CHANNEL_CONF channels = al_get_voice_channels(_ts5_status.audio_status.voice);
135 
136  unsigned int retval;
137 
138  if (channels == ALLEGRO_CHANNEL_CONF_1) {
139  retval = TS5_MONO;
140  }
141  else if (channels == ALLEGRO_CHANNEL_CONF_2) {
142  retval = TS5_STEREO;
143  }
144  else {
145  ts5_fatal("ts5_get_audio_channels: got an unknonwn number of channels\n");
146  retval = 0;
147  }
148 
149  return retval;
150 }
151 
152 
173 int ts5_set_audio_depth(int depth)
174 {
175  if (!_ts5_is_tscope5_installed) {
176  ts5_install_tscope5("ts5_set_audio_depth");
177  }
178 
179  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_depth(%d)\n", depth);
180 
181  int retval = _ts5_status.audio_status.depth;
182 
183  if (depth!=TS5_INTEGER && depth!=TS5_FLOAT) {
184  ts5_fatal("ts5_set_audio_depth: unknonwn sample depth requested\n");
185  }
186 
187  _ts5_status.audio_status.depth = depth;
188 
189  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_depth: set sample depth to %d (was %d)\n",
190  _ts5_status.audio_status.depth, retval);
191 
192  return retval;
193 }
194 
195 
202 {
203  ts5_check_audio("ts5_get_audio_depth");
204  ts5_log(TS5_LOGLEVEL_4, "ts5_get_audio_depth()\n");
205 
206  ALLEGRO_AUDIO_DEPTH depth = al_get_voice_depth(_ts5_status.audio_status.voice);
207 
208  if (depth != TS5_INTEGER && depth !=TS5_FLOAT) {
209  ts5_fatal("ts5_get_audio_depth: got an unknonwn sample depth\n");
210  }
211 
212  return depth;
213 }
214 
215 
225 double ts5_set_audio_gain(double gain)
226 {
227  if (!_ts5_is_tscope5_installed) {
228  ts5_install_tscope5("ts5_set_audio_gain");
229  }
230 
231  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_gain(%f)\n", gain);
232 
233  double retval = _ts5_status.audio_status.gain;
234 
235  if (gain<0.0) {
236  ts5_fatal("ts5_set_audio_gain: gain should be >= 0.0\n");
237  }
238 
239  _ts5_status.audio_status.gain = gain;
240 
241  if (!al_set_mixer_gain(_ts5_status.audio_status.mixer, gain)) {
242  ts5_fatal("ts5_set_audio_gain: could not change audio gain\n");
243  }
244 
245  ts5_log(TS5_LOGLEVEL_4, "ts5_set_audio_gain: set gain to %f (was %f)\n",
246  _ts5_status.audio_status.gain, retval);
247 
248  return retval;
249 }
250 
251 
258 {
259  ts5_check_audio("ts5_get_audio_gain");
260  ts5_log(TS5_LOGLEVEL_4, "ts5_get_audio_gain()\n");
261 
262  return _ts5_status.audio_status.gain;
263 }
264 
265 
267 
268 
269 
270 
281 
282 
283 
284 
295 TS5_SAMPLE *ts5_alloc_sample(double length)
296 {
297  ts5_check_audio("ts5_alloc_sample");
298  ts5_log(TS5_LOGLEVEL_2, "ts5_alloc_sample(%f)\n", length);
299 
300  unsigned int samples = length * _ts5_status.audio_status.frequency;
301 
302  ALLEGRO_CHANNEL_CONF channels;
303 
304  if (_ts5_status.audio_status.channels==TS5_MONO) {
305  channels=ALLEGRO_CHANNEL_CONF_1;
306  }
307  else if (_ts5_status.audio_status.channels==TS5_STEREO) {
308  channels=ALLEGRO_CHANNEL_CONF_2;
309  }
310  else {
311  ts5_fatal("ts5_alloc_sample: unknonwn channel configuration requested\n");
312  }
313 
314  unsigned int sample_size = al_get_channel_count(channels) *
315  al_get_audio_depth_size(_ts5_status.audio_status.depth);
316 
317  unsigned int bytes = samples * sample_size;
318 
319  void *buff = NULL;
320  buff = al_malloc(bytes);
321 
322  if (!buff) {
323  ts5_fatal("ts5_alloc_sample: could not allocate sample buffer\n");
324  }
325 
326  TS5_SAMPLE *sample = NULL;
327  sample = (TS5_SAMPLE *)al_malloc(sizeof(TS5_SAMPLE));
328 
329  if (!sample) {
330  ts5_fatal("ts5_alloc_sample: could not allocate sample\n");
331  }
332 
333  sample->sample = al_create_sample(buff, samples, _ts5_status.audio_status.frequency,
334  _ts5_status.audio_status.depth, channels, true);
335 
336  if (!sample->sample) {
337  ts5_fatal("ts5_alloc_sample: could not create sample\n");
338  }
339 
340  sample->instance = al_create_sample_instance(NULL);
341 
342  if (!sample->instance) {
343  ts5_fatal("ts5_alloc_sample: could not create sample instance\n");
344  }
345 
346  if (!al_set_sample(sample->instance, sample->sample)) {
347  ts5_fatal("ts5_alloc_sample: could not attach sample to sample instance\n");
348  }
349 
350  if (!al_attach_sample_instance_to_mixer(sample->instance, _ts5_status.audio_status.mixer)) {
351  ts5_fatal("ts5_alloc_sample: could not attach sample instance to mixer\n");
352  }
353 
354  al_set_sample_instance_playing(sample->instance, false);
355 
356  sample->issample = true;
357  sample->isfilestream = false;
358  sample->ismemorystream = false;
359  sample->stream = NULL;
360 
361  return sample;
362 }
363 
364 
376 TS5_SAMPLE *ts5_read_sample(const char *file)
377 {
378  ts5_check_audio("ts5_read_sample");
379  ts5_log(TS5_LOGLEVEL_2, "ts5_read_sample(%s)\n", file);
380 
381  TS5_SAMPLE *sample = NULL;
382  sample = (TS5_SAMPLE *)al_malloc(sizeof(TS5_SAMPLE));
383 
384  if (!sample) {
385  ts5_fatal("ts5_read_sample: could not allocate sample\n");
386  }
387 
388  sample->issample = true;
389  sample->isfilestream = false;
390  sample->ismemorystream = false;
391 
392  sample->sample = NULL;
393  sample->sample = al_load_sample(file);
394 
395  if (!sample->sample) {
396  ts5_fatal("ts5_read_sample: could not read sample\n");
397  }
398 
399  sample->instance = NULL;
400  sample->instance = al_create_sample_instance(NULL);
401 
402  if (!sample->instance) {
403  ts5_fatal("ts5_read_sample: could not create sample instance\n");
404  }
405 
406  if (!al_set_sample(sample->instance, sample->sample)) {
407  ts5_fatal("ts5_read_sample: could not attach sample to sample instance\n");
408  }
409 
410  if (!al_attach_sample_instance_to_mixer(sample->instance, _ts5_status.audio_status.mixer)) {
411  ts5_fatal("ts5_read_sample: could not attach sample instance to mixer\n");
412  }
413 
414  al_set_sample_instance_playing(sample->instance, false);
415 
416  sample->stream = NULL;
417 
418  return sample;
419 }
420 
421 
433 TS5_SAMPLE *ts5_read_long_sample(const char *file)
434 {
435  ts5_check_audio("ts5_read_long_sample");
436  ts5_log(TS5_LOGLEVEL_2, "ts5_read_long_sample(%s)\n", file);
437 
438  TS5_SAMPLE *sample = NULL;
439  sample = (TS5_SAMPLE *)al_malloc(sizeof(TS5_SAMPLE));
440 
441  if (!sample) {
442  ts5_fatal("ts5_read_long_sample: could not allocate sample\n");
443  }
444 
445  sample->issample = false;
446  sample->isfilestream = true;
447  sample->ismemorystream = false;
448 
449  sample->sample = NULL;
450  sample->instance = NULL;
451 
452  sample->stream = NULL;
453  sample->stream = al_load_audio_stream(file, 4, 2048);
454 
455  if (!sample->stream) {
456  ts5_fatal("ts5_read_long_sample: could not read sample\n");
457  }
458 
459  if (!al_attach_audio_stream_to_mixer(sample->stream, _ts5_status.audio_status.mixer)) {
460  ts5_fatal("ts5_read_long_sample: could not attach sample stream to mixer\n");
461  }
462 
463  al_set_audio_stream_playing(sample->stream, false);
464  al_set_audio_stream_playmode(sample->stream, ALLEGRO_PLAYMODE_ONCE);
465 
466  return sample;
467 }
468 
469 
478 void ts5_write_sample(const char *file, TS5_SAMPLE *sample)
479 {
480  ts5_check_audio("ts5_write_sample");
481  ts5_log(TS5_LOGLEVEL_2, "ts5_write_sample(%s,%p)\n", file, sample);
482 
483  if (!sample->issample) {
484  ts5_fatal("ts5_write_sample: writing of streams is not implemented yet\n");
485  }
486 
487  if (!al_save_sample(file, sample->sample)) {
488  ts5_fatal("ts5_write_sample: could not write sample\n");
489  }
490 }
491 
492 
501 void ts5_free_sample(TS5_SAMPLE *sample)
502 {
503  ts5_check_audio("ts5_free_sample");
504  ts5_log(TS5_LOGLEVEL_2, "ts5_free_sample(%p)\n", sample);
505 
506  if (sample->issample) {
507  al_set_sample(sample->instance, NULL);
508  al_destroy_sample(sample->sample);
509 
510  al_detach_sample_instance(sample->instance);
511  al_destroy_sample_instance(sample->instance);
512  }
513  else if (sample->isfilestream) {
514  al_detach_audio_stream(sample->stream);
515  al_destroy_audio_stream(sample->stream);
516  }
517  else if (sample->ismemorystream) {
518  ts5_fatal("ts5_free_sample: memory streams not implemented yet\n");
519  }
520 
521  al_free(sample);
522 }
523 
524 
526 
527 
528 
529 
537 
538 
539 
540 
546 void ts5_play_sample(TS5_SAMPLE *sample)
547 {
548  ts5_check_audio("ts5_play_sample");
549  ts5_log(TS5_LOGLEVEL_5, "ts5_play_sample(%p)\n", sample);
550 
551  if (!sample) {
552  ts5_fatal("ts5_play_sample: sample pointer is null\n");
553  }
554 
555  if (sample->issample) {
556 
557  if (!al_set_sample_instance_playing(sample->instance, 1)) {
558  ts5_fatal("ts5_play_sample: could not play sample\n");
559  }
560  }
561  else if (sample->isfilestream) {
562 
563  if (!al_set_audio_stream_playing(sample->stream, 1)) {
564  ts5_fatal("ts5_play_sample: could not play sample\n");
565  }
566  }
567  else if (sample->ismemorystream) {
568  ts5_fatal("ts5_play_sample: memory streams not implemented yet\n");
569  }
570 }
571 
572 
578 void ts5_pause_sample(TS5_SAMPLE *sample)
579 {
580  ts5_check_audio("ts5_pause_sample");
581  ts5_log(TS5_LOGLEVEL_5, "ts5_pause_sample(%p)\n", sample);
582 
583  if (!sample) {
584  ts5_fatal("ts5_pause_sample: sample pointer is null\n");
585  }
586 
587  if (sample->issample) {
588 
589  unsigned int position = al_get_sample_instance_position(sample->instance);
590 
591  if (!al_set_sample_instance_playing(sample->instance, 0)) {
592  ts5_fatal("ts5_pause_sample: could not pause sample\n");
593  }
594 
595  if (!al_set_sample_instance_position(sample->instance, position)) {
596  ts5_fatal("ts5_pause_sample: could not change sample position\n");
597  }
598  }
599  else if (sample->isfilestream) {
600 
601  if (!al_set_audio_stream_playing(sample->stream, 0)) {
602  ts5_fatal("ts5_pause_sample: could not pause sample\n");
603  }
604  }
605  else if (sample->ismemorystream) {
606  ts5_fatal("memory streams not implemented yet\n");
607  }
608 }
609 
610 
616 void ts5_stop_sample(TS5_SAMPLE *sample)
617 {
618  ts5_check_audio("ts5_stop_sample");
619  ts5_log(TS5_LOGLEVEL_5, "ts5_stop_sample(%p)\n", sample);
620 
621  if (!sample) {
622  ts5_fatal("ts5_stop_sample: sample pointer is null\n");
623  }
624 
625  if (sample->issample) {
626 
627  if (!al_set_sample_instance_playing(sample->instance, 0)) {
628  ts5_fatal("ts5_stop_sample: could not stop sample\n");
629  }
630 
631  if (!al_set_sample_instance_position(sample->instance, 0)) {
632  ts5_fatal("ts5_stop_sample: could not stop sample\n");
633  }
634  }
635  else if (sample->isfilestream) {
636 
637  al_drain_audio_stream(sample->stream);
638 
639  if (!al_rewind_audio_stream(sample->stream)) {
640  ts5_fatal("ts5_stop_sample: could not rewind sample\n");
641  }
642  }
643  else if (sample->ismemorystream) {
644  ts5_fatal("ts5_stop_sample: memory streams not implemented yet\n");
645  }
646 }
647 
648 
650 
651 
652 
653 
663 
664 
665 
666 
674 int ts5_get_sample_status(TS5_SAMPLE *sample)
675 {
676  ts5_check_audio("ts5_get_sample_status");
677  ts5_log(TS5_LOGLEVEL_5, "ts5_get_sample_status(%p)\n", sample);
678 
679  if (!sample) {
680  ts5_fatal("ts5_get_sample_status: sample pointer is null\n");
681  }
682 
683  int retval = 0;
684 
685  if (sample->issample) {
686  retval = al_get_sample_instance_playing(sample->instance);
687  }
688  else if (sample->isfilestream) {
689  retval = al_get_audio_stream_playing(sample->stream);
690  }
691  else if (sample->ismemorystream) {
692  ts5_fatal("ts5_get_sample_status: memory streams not implemented yet\n");
693  }
694  else {
695  ts5_fatal("ts5_get_sample_status: sample type unknown\n");
696  }
697 
698  return retval;
699 }
700 
701 
709 unsigned int ts5_get_sample_frequency(TS5_SAMPLE *sample)
710 {
711  ts5_check_audio("ts5_get_sample_frequency");
712  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_frequency(%p)\n", sample);
713 
714  if (!sample) {
715  ts5_fatal("ts5_get_sample_frequency: sample pointer is null\n");
716  }
717 
718  unsigned int retval = 0;
719 
720  if (sample->issample) {
721  retval = al_get_sample_frequency(sample->sample);
722  }
723  else if (sample->isfilestream) {
724  retval = al_get_audio_stream_frequency(sample->stream);
725  }
726  else if (sample->ismemorystream) {
727  ts5_fatal("ts5_get_sample_frequency: memory streams not implemented yet\n");
728  }
729 
730  return retval;
731 }
732 
733 
741 unsigned int ts5_get_sample_channels(TS5_SAMPLE *sample)
742 {
743  ts5_check_audio("ts5_get_sample_channels");
744  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_channels(%p)\n", sample);
745 
746  if (!sample) {
747  ts5_fatal("ts5_get_sample_channels: sample pointer is null\n");
748  }
749 
750  ALLEGRO_CHANNEL_CONF channels;
751 
752  if (sample->issample) {
753  channels = al_get_sample_channels(sample->sample);
754  }
755  else if (sample->isfilestream) {
756  channels = al_get_audio_stream_channels(sample->stream);
757  }
758  else if (sample->ismemorystream) {
759  ts5_fatal("ts5_get_sample_channels: memory streams not implemented yet\n");
760  }
761 
762  unsigned int retval = 0;
763 
764  if (channels == ALLEGRO_CHANNEL_CONF_1) {
765  retval = TS5_MONO;
766  }
767  else if (channels == ALLEGRO_CHANNEL_CONF_2) {
768  retval = TS5_STEREO;
769  }
770  else {
771  ts5_fatal("ts5_get_sample_channels: got an unknonwn number of channels\n");
772  }
773 
774  return retval;
775 }
776 
777 
785 int ts5_get_sample_depth(TS5_SAMPLE *sample)
786 {
787  ts5_check_audio("ts5_get_sample_depth");
788  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_depth(%p)\n", sample);
789 
790  if (!sample) {
791  ts5_fatal("ts5_get_sample_depth: sample pointer is null\n");
792  }
793 
794  ALLEGRO_AUDIO_DEPTH depth;
795 
796  if (sample->issample) {
797  depth = al_get_sample_depth(sample->sample);
798  }
799  else if (sample->isfilestream) {
800  depth = al_get_audio_stream_depth(sample->stream);
801  }
802  else if (sample->ismemorystream) {
803  ts5_fatal("ts5_get_sample_depth: memory streams not implemented yet\n");
804  }
805 
806  int retval = 0;
807 
808  if (depth == ALLEGRO_AUDIO_DEPTH_INT16) {
809  retval = TS5_INTEGER;
810  }
811  else if (depth == ALLEGRO_AUDIO_DEPTH_FLOAT32) {
812  retval = TS5_FLOAT;
813  }
814  else {
815  ts5_fatal("ts5_get_audio_depth: got an unknonwn sample depth\n");
816  }
817 
818  return retval;
819 }
820 
821 
829 unsigned int ts5_get_sample_length(TS5_SAMPLE *sample)
830 {
831  ts5_check_audio("ts5_get_sample_length");
832  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_length(%p)\n", sample);
833 
834  if (!sample) {
835  ts5_fatal("ts5_get_sample_length: sample pointer is null\n");
836  }
837 
838  unsigned int retval = 0;
839 
840  if (sample->issample) {
841  retval = al_get_sample_length(sample->sample);
842  }
843  else if (sample->isfilestream) {
844  retval = al_get_audio_stream_length(sample->stream);
845  }
846  else if (sample->ismemorystream) {
847  ts5_fatal("ts5_get_sample_length: memory streams not implemented yet\n");
848  }
849 
850  return retval;
851 }
852 
853 
854 
863 unsigned int ts5_set_sample_position(TS5_SAMPLE *sample, unsigned int position)
864 {
865  ts5_check_audio("ts5_set_sample_position");
866  ts5_log(TS5_LOGLEVEL_4, "ts5_set_sample_position(%p,%u)\n", sample, position);
867 
868  if (!sample) {
869  ts5_fatal("ts5_set_sample_position: sample pointer is null\n");
870  }
871 
872  unsigned int retval= 0;
873 
874  if (sample->issample) {
875 
876  unsigned int max = al_get_sample_length(sample->sample);
877 
878  if (position > max) {
879  ts5_fatal("ts5_set_sample_position: position should be",
880  " <= the length of the sample (%d)\n", max);
881  }
882 
883  retval = al_get_sample_instance_position(sample->instance);
884 
885  if (!(al_set_sample_instance_position(sample->instance, position))) {
886  ts5_fatal("ts5_set_sample_position: could not change sample position\n");
887  }
888  }
889  else if (sample->isfilestream) {
890 
891  unsigned int freq = al_get_audio_stream_frequency(sample->stream);
892  unsigned int max = al_get_audio_stream_length_secs(sample->stream) * freq;
893 
894  if (position > max) {
895  ts5_fatal("ts5_set_sample_position: position should be",
896  " <= the length of the sample (%d)\n", max);
897  }
898 
899  retval = al_get_audio_stream_position_secs(sample->stream) * freq;
900 
901  if (!(al_seek_audio_stream_secs(sample->stream, position / freq))) {
902  ts5_fatal("ts5_set_sample_position: could not change sample position\n");
903  }
904  }
905  else if (sample->ismemorystream) {
906  ts5_fatal("ts5_set_sample_position: memory streams not implemented yet\n");
907  }
908 
909  return retval;
910 }
911 
912 
920 unsigned int ts5_get_sample_position(TS5_SAMPLE *sample)
921 {
922  ts5_check_audio("ts5_get_sample_position");
923  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_position(%p)\n", sample);
924 
925  if (!sample) {
926  ts5_fatal("ts5_get_sample_length: sample pointer is null\n");
927  }
928 
929  unsigned int retval = 0;
930 
931  if (sample->issample) {
932  retval = al_get_sample_instance_position(sample->instance);
933  }
934  else if (sample->isfilestream) {
935  unsigned int freq = al_get_audio_stream_frequency(sample->stream);
936  retval = al_get_audio_stream_position_secs(sample->stream) * freq;
937  }
938  else if (sample->ismemorystream) {
939  ts5_fatal("ts5_get_sample_position: memory streams not implemented yet\n");
940  }
941 
942  return retval;
943 }
944 
945 
954 double ts5_set_sample_speed(TS5_SAMPLE *sample, double speed)
955 {
956  ts5_check_audio("ts5_set_sample_speed");
957  ts5_log(TS5_LOGLEVEL_4, "ts5_set_sample_speed(%p,%f)\n", sample, speed);
958 
959  if (!sample) {
960  ts5_fatal("ts5_set_sample_speed: sample pointer is null\n");
961  }
962 
963  if (speed < 0) {
964  ts5_fatal("ts5_set_sample_speed: speed should be >0 (is %f)\n", speed);
965  }
966 
967  double retval = 0.0;
968 
969  if (sample->issample) {
970 
971  retval = al_get_sample_instance_speed(sample->instance);
972 
973  if (!(al_set_sample_instance_speed(sample->instance, speed))) {
974  ts5_fatal("ts5_set_sample_speed: could not change sample speed (%f)\n", speed);
975  }
976  }
977  else if (sample->isfilestream) {
978 
979  retval = al_get_audio_stream_speed(sample->stream);
980 
981  if (!(al_set_audio_stream_speed(sample->stream, speed))) {
982  ts5_fatal("ts5_set_sample_speed: could not change sample speed (%f)\n", speed);
983  }
984  }
985  else if (sample->ismemorystream) {
986  ts5_fatal("memory streams not implemented yet\n");
987  }
988 
989  return retval;
990 }
991 
992 
1000 double ts5_get_sample_speed(TS5_SAMPLE *sample)
1001 {
1002  ts5_check_audio("ts5_get_sample_speed");
1003  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_speed(%p)\n", sample);
1004 
1005  if (!sample) {
1006  ts5_fatal("ts5_get_sample_speed: sample pointer is null\n");
1007  }
1008 
1009  double retval = 0.0;
1010 
1011  if (sample->issample) {
1012  retval = al_get_sample_instance_speed(sample->instance);
1013  }
1014  else if (sample->isfilestream) {
1015  retval = al_get_audio_stream_speed(sample->stream);
1016  }
1017  else if (sample->ismemorystream) {
1018  ts5_fatal("ts5_get_sample_speed: memory streams not implemented yet\n");
1019  }
1020 
1021  return retval;
1022 }
1023 
1024 
1033 double ts5_set_sample_gain(TS5_SAMPLE *sample, double gain)
1034 {
1035  ts5_check_audio("ts5_set_sample_gain");
1036  ts5_log(TS5_LOGLEVEL_4, "ts5_set_sample_gain(%p,%f)\n", sample, gain);
1037 
1038  if (!sample) {
1039  ts5_fatal("ts5_set_sample_gain: sample pointer is null\n");
1040  }
1041 
1042  if (gain < 0) {
1043  ts5_fatal("ts5_set_sample_gain: gain should be >0 (is %f)\n", gain);
1044  }
1045 
1046  double retval = 0.0;
1047 
1048  if (sample->issample) {
1049 
1050  retval = al_get_sample_instance_gain(sample->instance);
1051 
1052  if (!(al_set_sample_instance_gain(sample->instance, gain))) {
1053  ts5_fatal("ts5_set_sample_gain: could not change sample gain (%f)\n", gain);
1054  }
1055  }
1056  else if (sample->isfilestream) {
1057 
1058  retval = al_get_audio_stream_gain(sample->stream);
1059 
1060  if (!(al_set_audio_stream_gain(sample->stream, gain))) {
1061  ts5_fatal("ts5_set_sample_gain: could not change sample gain (%f)\n", gain);
1062  }
1063  }
1064  else if (sample->ismemorystream) {
1065  ts5_fatal("memory streams not implemented yet\n");
1066  }
1067 
1068  return retval;
1069 }
1070 
1071 
1079 double ts5_get_sample_gain(TS5_SAMPLE *sample)
1080 {
1081  ts5_check_audio("ts5_get_sample_gain");
1082  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_gain(%p)\n", sample);
1083 
1084  if (!sample) {
1085  ts5_fatal("ts5_get_sample_gain: sample pointer is null\n");
1086  }
1087 
1088  double retval = 0.0;
1089 
1090  if (sample->issample) {
1091  retval = al_get_sample_instance_gain(sample->instance);
1092  }
1093  else if (sample->isfilestream) {
1094  retval = al_get_audio_stream_gain(sample->stream);
1095  }
1096  else if (sample->ismemorystream) {
1097  ts5_fatal("ts5_get_sample_gain: memory streams not implemented yet\n");
1098  }
1099 
1100  return retval;
1101 }
1102 
1103 
1112 double ts5_set_sample_pan(TS5_SAMPLE *sample, double pan)
1113 {
1114  ts5_check_audio("ts5_set_sample_pan");
1115  ts5_log(TS5_LOGLEVEL_4, "ts5_set_sample_pan(%p,%f)\n", sample, pan);
1116 
1117  if (!sample) {
1118  ts5_fatal("ts5_set_sample_pan: sample pointer is null\n");
1119  }
1120 
1121  if (pan < -1.0 || pan > 1) {
1122  ts5_fatal("ts5_set_sample_pan: pan should be between -1.0 and 1.0 (is %f)\n", pan);
1123  }
1124 
1125  double retval = 0.0;
1126 
1127  if (sample->issample) {
1128 
1129  retval = al_get_sample_instance_pan(sample->instance);
1130 
1131  if (!(al_set_sample_instance_pan(sample->instance, pan))) {
1132  ts5_fatal("ts5_set_sample_pan: could not change sample pan (%f)\n", pan);
1133  }
1134  }
1135  else if (sample->isfilestream) {
1136 
1137  retval = al_get_audio_stream_pan(sample->stream);
1138 
1139  if (!(al_set_audio_stream_pan(sample->stream, pan))) {
1140  ts5_fatal("ts5_set_sample_pan: could not change sample pan (%f)\n", pan);
1141  }
1142  }
1143  else if (sample->ismemorystream) {
1144  ts5_fatal("ts5_set_sample_pan: memory streams not implemented yet\n");
1145  }
1146 
1147  return retval;
1148 }
1149 
1150 
1158 double ts5_get_sample_pan(TS5_SAMPLE *sample)
1159 {
1160  ts5_check_audio("ts5_get_sample_pan");
1161  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_pan(%p)\n", sample);
1162 
1163  if (!sample) {
1164  ts5_fatal("ts5_get_sample_pan: sample pointer is null\n");
1165  }
1166 
1167  double retval = 0.0;
1168 
1169  if (sample->issample) {
1170  retval = al_get_sample_instance_pan(sample->instance);
1171  }
1172  else if (sample->isfilestream) {
1173  retval = al_get_audio_stream_pan(sample->stream);
1174  }
1175  else if (sample->ismemorystream) {
1176  ts5_fatal("memory streams not implemented yet\n");
1177  }
1178 
1179  return retval;
1180 }
1181 
1182 
1191 int ts5_set_sample_playmode(TS5_SAMPLE *sample, int playmode)
1192 {
1193  ts5_check_audio("ts5_set_sample_playmode");
1194  ts5_log(TS5_LOGLEVEL_4, "ts5_set_sample_playmode(%p,%d)\n", sample, playmode);
1195 
1196  if (!sample) {
1197  ts5_fatal("ts5_set_sample_playmode: sample pointer is null\n");
1198  }
1199 
1200  if (playmode != TS5_PLAY_ONCE && playmode != TS5_PLAY_LOOP) {
1201  ts5_fatal("ts5_set_sample_playmode: playmode should be TS5_PLAY_ONCE or TS5_PLAY_LOOP\n");
1202  }
1203 
1204  int retval = 0;
1205 
1206  if (sample->issample) {
1207 
1208  retval = al_get_sample_instance_playmode(sample->instance);
1209 
1210  if (!(al_set_sample_instance_playmode(sample->instance, playmode))) {
1211  ts5_fatal("ts5_set_sample_playmode: could not change sample playmode\n");
1212  }
1213  }
1214  else if (sample->isfilestream) {
1215 
1216  retval = al_get_audio_stream_playmode(sample->stream) - 3;
1217 
1218  if (!(al_set_audio_stream_playmode(sample->stream, playmode))) {
1219  ts5_fatal("ts5_set_sample_playmode: could not change sample playmode\n");
1220  }
1221  }
1222  else if (sample->ismemorystream) {
1223  ts5_fatal("ts5_set_sample_playmode: memory streams not implemented yet\n");
1224  }
1225 
1226  return retval;
1227 }
1228 
1229 
1237 int ts5_get_sample_playmode(TS5_SAMPLE *sample)
1238 {
1239  ts5_check_audio("ts5_get_sample_playmode");
1240  ts5_log(TS5_LOGLEVEL_4, "ts5_get_sample_playmode(%p)\n", sample);
1241 
1242  if (!sample) {
1243  ts5_fatal("ts5_get_sample_playmode: sample pointer is null\n");
1244  }
1245 
1246  int retval = 0;
1247 
1248  if (sample->issample) {
1249  retval = al_get_sample_instance_playmode(sample->instance);
1250  }
1251  else if (sample->isfilestream) {
1252  retval = al_get_audio_stream_playmode(sample->stream) - 3;
1253  }
1254  else if (sample->ismemorystream) {
1255  ts5_fatal("ts5_get_sample_playmode: memory streams not implemented yet\n");
1256  }
1257 
1258  return retval;
1259 }
1260 
1261 
1263 
1264 
1265