source: roaraudio/roarfish/play.c @ 485:efebd5911d51

Last change on this file since 485:efebd5911d51 was 379:e4206d78c257, checked in by phi, 16 years ago

make playback work :)

File size: 1.8 KB
Line 
1//play.c:
2
3#include "roarfish.h"
4
5struct roarfish_play_inst {
6 int roarfh;
7 int begun;
8 FishSoundInfo fsinfo;
9 FishSound * fsound;
10};
11
12int decoded_float (FishSound * fsound, float ** pcm, long frames, void * user_data) {
13 struct roarfish_play_inst * inst = (struct roarfish_play_inst*) user_data;
14 int16_t * data;
15 int i;
16 double s;
17
18 if (!inst->begun) {
19   fish_sound_command (fsound, FISH_SOUND_GET_INFO, &(inst->fsinfo),
20                       sizeof (FishSoundInfo));
21   if ( (inst->roarfh = roar_simple_play(inst->fsinfo.samplerate, inst->fsinfo.channels,
22                                         16, ROAR_CODEC_NATIVE, NULL, "roarfish")) == -1 ) {
23    return -1;
24   }
25   inst->begun = 1;
26 }
27
28 if ( (data = malloc(frames*2*inst->fsinfo.channels)) == NULL ) {
29  return -1;
30 }
31
32 frames *= inst->fsinfo.channels;
33
34 for (i = 0; i < frames; i++) {
35  s  = ((float*)pcm)[i];
36  s *= 32767;
37  data[i] = s;
38 }
39
40
41 write(inst->roarfh, (char*)data, frames * 2);
42
43
44 free(data);
45
46 return 0;
47}
48
49int read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) {
50 FishSound * fsound = (FishSound *)user_data;
51
52 fish_sound_prepare_truncation (fsound, op->granulepos, op->e_o_s);
53 fish_sound_decode (fsound, op->packet, op->bytes);
54
55 return 0;
56}
57
58int play (char * file, char ** opts) {
59 OGGZ * oggz;
60 struct roarfish_play_inst inst;
61
62 inst.roarfh = -1;
63 inst.begun  = 0;
64
65 inst.fsound = fish_sound_new(FISH_SOUND_DECODE, &inst.fsinfo);
66 fish_sound_set_interleave(inst.fsound, 1);
67
68 fish_sound_set_decoded_float_ilv(inst.fsound, decoded_float, (void*)&inst);
69
70 if ((oggz = oggz_open(file, OGGZ_READ)) == NULL) {
71  ROAR_ERR("Can not open input file: %s", file);
72  return -1;
73 }
74
75 oggz_set_read_callback(oggz, -1, read_packet, inst.fsound);
76
77 // TODO: add some status display here?
78 while (oggz_read(oggz, 1024));
79
80 oggz_close(oggz);
81
82 fish_sound_delete(inst.fsound);
83
84 return -1;
85}
86
87//ll
Note: See TracBrowser for help on using the repository browser.