~ubuntu-branches/ubuntu/breezy/soundtracker/breezy

« back to all changes in this revision

Viewing changes to app/drivers/file-output.c

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2005-04-18 07:19:14 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050418071914-b9m1ptfdnz8mqm7a
Tags: 0.6.7-5
* disable alsa (closes: #286350, #304711)
- it was doing double-free.
* update jack support, not enabled.
- 02_jack_output: Patch from Kai Vehmanen available as
  http://eca.cx/download/soundtracker-0.6.7-pre6-kv3.tar.gz
  applied.
- Build-Depend on libjack0.80.0-dev
- remove --disable-jack from configure line
* change soundtracker.1 section from 1x to 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include <config.h>
23
23
 
24
 
#ifndef NO_AUDIOFILE
 
24
#if USE_SNDFILE
 
25
 
 
26
#include <stdio.h>
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
#include <errno.h>
 
30
 
 
31
#include <sys/types.h>
 
32
#include <unistd.h>
 
33
 
 
34
#include <sndfile.h>
 
35
 
 
36
#include "i18n.h"
 
37
#include "driver-out.h"
 
38
#include "mixer.h"
 
39
#include "errors.h"
 
40
#include "gui-subs.h"
 
41
#include "preferences.h"
 
42
 
 
43
typedef struct sndfile_driver {
 
44
    gchar *filename; /* must be the first entry. is altered by audio.c (hack, hack) */
 
45
 
 
46
    SNDFILE *outfile;
 
47
    SF_INFO sfinfo;
 
48
 
 
49
    int pipe[2];
 
50
    gpointer polltag;
 
51
    int firstpoll;
 
52
 
 
53
    gint16 *sndbuf;
 
54
    int sndbuf_size;
 
55
    double playtime;
 
56
 
 
57
    int p_resolution;
 
58
    int p_channels;
 
59
    int p_mixfreq;
 
60
 
 
61
    GtkWidget *configwidget;
 
62
} sndfile_driver;
 
63
 
 
64
static void
 
65
sndfile_poll_ready_playing (gpointer data,
 
66
                         gint source,
 
67
                         GdkInputCondition condition)
 
68
{
 
69
    sndfile_driver * const d = data;
 
70
 
 
71
    if(!d->firstpoll) {
 
72
        sf_writef_short (d->outfile, d->sndbuf, d->sndbuf_size / 4);
 
73
        d->playtime += (double)(d->sndbuf_size) / 4 / d->p_mixfreq;
 
74
    }
 
75
 
 
76
    d->firstpoll = FALSE;
 
77
#ifdef WORDS_BIGENDIAN
 
78
    audio_mix(d->sndbuf, d->sndbuf_size / 4, d->p_mixfreq, ST_MIXER_FORMAT_S16_BE | ST_MIXER_FORMAT_STEREO);
 
79
#else
 
80
    audio_mix(d->sndbuf, d->sndbuf_size / 4, d->p_mixfreq, ST_MIXER_FORMAT_S16_LE | ST_MIXER_FORMAT_STEREO);
 
81
#endif
 
82
 
 
83
}
 
84
 
 
85
static void
 
86
sndfile_make_config_widgets (sndfile_driver *d)
 
87
{
 
88
    GtkWidget *thing, *mainbox;
 
89
 
 
90
    d->configwidget = mainbox = gtk_vbox_new(FALSE, 2);
 
91
   
 
92
    thing = gtk_label_new(_("no settings (yet), sorry!"));
 
93
    gtk_box_pack_start(GTK_BOX(mainbox), thing, FALSE, TRUE, 0);
 
94
    gtk_widget_show(thing);
 
95
}
 
96
 
 
97
static GtkWidget *
 
98
sndfile_getwidget (void *dp)
 
99
{
 
100
    sndfile_driver * const d = dp;
 
101
 
 
102
    return d->configwidget;
 
103
}
 
104
 
 
105
static void *
 
106
sndfile_new (void)
 
107
{
 
108
    sndfile_driver *d = g_new(sndfile_driver, 1);
 
109
 
 
110
    d->p_mixfreq = 44100;
 
111
    d->p_channels = 2;
 
112
    d->p_resolution = 16;
 
113
    d->sndbuf = NULL;
 
114
    d->polltag = NULL;
 
115
 
 
116
    sndfile_make_config_widgets(d);
 
117
 
 
118
    pipe(d->pipe);
 
119
 
 
120
    return d;
 
121
}
 
122
 
 
123
static void
 
124
sndfile_destroy (void *dp)
 
125
{
 
126
    sndfile_driver * const d = dp;
 
127
 
 
128
    close(d->pipe[0]);
 
129
    close(d->pipe[1]);
 
130
 
 
131
    gtk_widget_destroy(d->configwidget);
 
132
 
 
133
    g_free(d->filename);
 
134
 
 
135
    g_free(dp);
 
136
}
 
137
 
 
138
static void
 
139
sndfile_release (void *dp)
 
140
{
 
141
    sndfile_driver * const d = dp;
 
142
 
 
143
    free(d->sndbuf);
 
144
    d->sndbuf = NULL;
 
145
 
 
146
    audio_poll_remove(d->polltag);
 
147
    d->polltag = NULL;
 
148
 
 
149
    if(d->outfile != NULL) {
 
150
        sf_close(d->outfile);
 
151
        d->outfile = NULL;
 
152
    }
 
153
}
 
154
 
 
155
static gboolean
 
156
sndfile_open (void *dp)
 
157
{
 
158
    sndfile_driver * const d = dp;
 
159
 
 
160
    d->sfinfo.channels = 2 ;
 
161
    d->sfinfo.samplerate = 44100 ;
 
162
    d->sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 ;
 
163
 
 
164
    d->outfile = sf_open (d->filename, SFM_WRITE, &d->sfinfo);
 
165
 
 
166
    if(!d->outfile) {
 
167
        error_error(_("Can't open file for writing."));
 
168
        goto out;
 
169
    }
 
170
 
 
171
    /* In case we're running setuid root... */
 
172
    chown(d->filename, getuid(), getgid());
 
173
 
 
174
    d->sndbuf_size = 16384;
 
175
    d->sndbuf = malloc(d->sndbuf_size);
 
176
    if(!d->sndbuf) {
 
177
        error_error("Can't allocate mix buffer.");
 
178
        goto out;
 
179
    }
 
180
 
 
181
    d->polltag = audio_poll_add(d->pipe[1], GDK_INPUT_WRITE, sndfile_poll_ready_playing, d);
 
182
    d->firstpoll = TRUE;
 
183
    d->playtime = 0.0;
 
184
 
 
185
    return TRUE;
 
186
 
 
187
  out:
 
188
    sndfile_release(dp);
 
189
    return FALSE;
 
190
}
 
191
 
 
192
static double
 
193
sndfile_get_play_time (void *dp)
 
194
{
 
195
    sndfile_driver * const d = dp;
 
196
 
 
197
    return d->playtime;
 
198
}
 
199
 
 
200
static gboolean
 
201
sndfile_loadsettings (void *dp,
 
202
                   prefs_node *f)
 
203
{
 
204
//    sndfile_driver * const d = dp;
 
205
 
 
206
    return TRUE;
 
207
}
 
208
 
 
209
static gboolean
 
210
sndfile_savesettings (void *dp,
 
211
                   prefs_node *f)
 
212
{
 
213
//    sndfile_driver * const d = dp;
 
214
 
 
215
    return TRUE;
 
216
}
 
217
 
 
218
st_out_driver driver_out_file = {
 
219
    { "WAV Rendering Output using libsndfile",
 
220
 
 
221
      sndfile_new,
 
222
      sndfile_destroy,
 
223
 
 
224
      sndfile_open,
 
225
      sndfile_release,
 
226
 
 
227
      sndfile_getwidget,
 
228
      sndfile_loadsettings,
 
229
      sndfile_savesettings,
 
230
    },
 
231
 
 
232
    sndfile_get_play_time,
 
233
};
 
234
 
 
235
#elif !defined (NO_AUDIOFILE)
25
236
 
26
237
#include <stdio.h>
27
238
#include <stdlib.h>
104
315
    d->p_mixfreq = 44100;
105
316
    d->p_channels = 2;
106
317
    d->p_resolution = 16;
 
318
    d->sndbuf = NULL;
 
319
    d->polltag = NULL;
107
320
 
108
321
    file_make_config_widgets(d);
109
322