source: roaraudio/roarfish/play.c @ 2802:ba5a00746517

Last change on this file since 2802:ba5a00746517 was 702:adaa5cf03fc0, checked in by phi, 16 years ago

added copyright statements

File size: 2.7 KB
Line 
1//play.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roarfish a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roarfish.h"
26
27struct roarfish_play_inst {
28 int roarfh;
29 int begun;
30 FishSoundInfo fsinfo;
31 FishSound * fsound;
32};
33
34int decoded_float (FishSound * fsound, float ** pcm, long frames, void * user_data) {
35 struct roarfish_play_inst * inst = (struct roarfish_play_inst*) user_data;
36 int16_t * data;
37 int i;
38 double s;
39
40 if (!inst->begun) {
41   fish_sound_command (fsound, FISH_SOUND_GET_INFO, &(inst->fsinfo),
42                       sizeof (FishSoundInfo));
43   if ( (inst->roarfh = roar_simple_play(inst->fsinfo.samplerate, inst->fsinfo.channels,
44                                         16, ROAR_CODEC_NATIVE, NULL, "roarfish")) == -1 ) {
45    return -1;
46   }
47   inst->begun = 1;
48 }
49
50 if ( (data = malloc(frames*2*inst->fsinfo.channels)) == NULL ) {
51  return -1;
52 }
53
54 frames *= inst->fsinfo.channels;
55
56 for (i = 0; i < frames; i++) {
57  s  = ((float*)pcm)[i];
58  s *= 32767;
59  data[i] = s;
60 }
61
62
63 write(inst->roarfh, (char*)data, frames * 2);
64
65
66 free(data);
67
68 return 0;
69}
70
71int read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) {
72 FishSound * fsound = (FishSound *)user_data;
73
74 fish_sound_prepare_truncation (fsound, op->granulepos, op->e_o_s);
75 fish_sound_decode (fsound, op->packet, op->bytes);
76
77 return 0;
78}
79
80int play (char * file, char ** opts) {
81 OGGZ * oggz;
82 struct roarfish_play_inst inst;
83
84 inst.roarfh = -1;
85 inst.begun  = 0;
86
87 inst.fsound = fish_sound_new(FISH_SOUND_DECODE, &inst.fsinfo);
88 fish_sound_set_interleave(inst.fsound, 1);
89
90 fish_sound_set_decoded_float_ilv(inst.fsound, decoded_float, (void*)&inst);
91
92 if ((oggz = oggz_open(file, OGGZ_READ)) == NULL) {
93  ROAR_ERR("Can not open input file: %s", file);
94  return -1;
95 }
96
97 oggz_set_read_callback(oggz, -1, read_packet, inst.fsound);
98
99 // TODO: add some status display here?
100 while (oggz_read(oggz, 1024));
101
102 oggz_close(oggz);
103
104 fish_sound_delete(inst.fsound);
105
106 return -1;
107}
108
109//ll
Note: See TracBrowser for help on using the repository browser.