source: roaraudio/roarfish/play.c @ 5878:3b92b0d6ef9b

Last change on this file since 5878:3b92b0d6ef9b was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

File size: 2.9 KB
Line 
1//play.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2013
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 if ( roar_vs_write(inst->vss, (char*)data, frames * 2, NULL) != (ssize_t)(frames * 2) ) {
66  return -1;
67 }
68
69
70 roar_mm_free(data);
71
72 return 0;
73}
74
75int read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data) {
76 FishSound * fsound = (FishSound *)user_data;
77
78 (void)oggz, (void)serialno;
79
80 fish_sound_prepare_truncation(fsound, op->granulepos, op->e_o_s);
81 fish_sound_decode(fsound, op->packet, op->bytes);
82
83 return 0;
84}
85
86int play (const char * file, char ** opts) {
87 OGGZ * oggz;
88 struct roarfish_play_inst inst;
89
90 (void)opts;
91
92 inst.vss    = NULL;
93
94 inst.fsound = fish_sound_new(FISH_SOUND_DECODE, &inst.fsinfo);
95 fish_sound_set_interleave(inst.fsound, 1);
96
97 fish_sound_set_decoded_float_ilv(inst.fsound, decoded_float, (void*)&inst);
98
99 if ((oggz = oggz_open(file, OGGZ_READ)) == NULL) {
100  ROAR_ERR("Can not open input file: %s", file);
101  return -1;
102 }
103
104 oggz_set_read_callback(oggz, -1, read_packet, inst.fsound);
105
106 // TODO: add some status display here?
107 while (oggz_read(oggz, 1024));
108
109 oggz_close(oggz);
110
111 fish_sound_delete(inst.fsound);
112
113 if ( inst.vss != NULL )
114  roar_vs_close(inst.vss, ROAR_VS_FALSE, NULL);
115
116 return 0;
117}
118
119//ll
Note: See TracBrowser for help on using the repository browser.