source: roaraudio/roarfish/play.c @ 4908:1268f8d7b740

Last change on this file since 4908:1268f8d7b740 was 4908:1268f8d7b740, checked in by phi, 13 years ago

upgraded to VS

File size: 2.8 KB
Line 
1//play.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roarfish.h"
27
28struct roarfish_play_inst {
29 roar_vs_t * vss;
30 int _roarfh;
31 int _begun;
32 FishSoundInfo fsinfo;
33 FishSound * fsound;
34};
35
36int decoded_float (FishSound * fsound, float ** pcm, long frames, void * user_data) {
37 struct roarfish_play_inst * inst = (struct roarfish_play_inst*) user_data;
38 int16_t * data;
39 int i;
40 float s;
41
42 if (inst->vss == NULL) {
43   fish_sound_command (fsound, FISH_SOUND_GET_INFO, &(inst->fsinfo),
44                       sizeof (FishSoundInfo));
45
46   if ( (inst->vss = roar_vs_new_playback(NULL, "roarfish", inst->fsinfo.samplerate, inst->fsinfo.channels,
47                                          ROAR_CODEC_DEFAULT, 16, NULL)) == NULL ) {
48    return -1;
49   }
50 }
51
52 if ( (data = roar_mm_malloc(frames*2*inst->fsinfo.channels)) == NULL ) {
53  return -1;
54 }
55
56 frames *= inst->fsinfo.channels;
57
58 for (i = 0; i < frames; i++) {
59  s  = ((float*)pcm)[i];
60  s *= 32767.f;
61  data[i] = s;
62 }
63
64
65 roar_vs_write(inst->vss, (char*)data, frames * 2, NULL);
66
67
68 roar_mm_free(data);
69
70 return 0;
71}
72
73int read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) {
74 FishSound * fsound = (FishSound *)user_data;
75
76 fish_sound_prepare_truncation (fsound, op->granulepos, op->e_o_s);
77 fish_sound_decode (fsound, op->packet, op->bytes);
78
79 return 0;
80}
81
82int play (char * file, char ** opts) {
83 OGGZ * oggz;
84 struct roarfish_play_inst inst;
85
86 inst.vss    = NULL;
87
88 inst.fsound = fish_sound_new(FISH_SOUND_DECODE, &inst.fsinfo);
89 fish_sound_set_interleave(inst.fsound, 1);
90
91 fish_sound_set_decoded_float_ilv(inst.fsound, decoded_float, (void*)&inst);
92
93 if ((oggz = oggz_open(file, OGGZ_READ)) == NULL) {
94  ROAR_ERR("Can not open input file: %s", file);
95  return -1;
96 }
97
98 oggz_set_read_callback(oggz, -1, read_packet, inst.fsound);
99
100 // TODO: add some status display here?
101 while (oggz_read(oggz, 1024));
102
103 oggz_close(oggz);
104
105 fish_sound_delete(inst.fsound);
106
107 if ( inst.vss != NULL )
108  roar_vs_close(inst.vss, ROAR_VS_FALSE, NULL);
109
110 return 0;
111}
112
113//ll
Note: See TracBrowser for help on using the repository browser.