~ubuntu-branches/debian/squeeze/fluidsynth/squeeze

« back to all changes in this revision

Viewing changes to src/fluid_aufile.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Eisentraut
  • Date: 2008-05-26 16:43:17 UTC
  • mfrom: (3.1.4 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080526164317-1j2op08lmr7a6y8j
Tags: 1.0.8-1.1
* Non-maintainer upload.
* Fix bashism in debian/rules (closes: #478380)

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
13
 * Library General Public License for more details.
14
 
 *  
 
14
 *
15
15
 * You should have received a copy of the GNU Library General Public
16
16
 * License along with this library; if not, write to the Free
17
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
20
 
21
21
/* fluid_aufile.c
22
22
 *
23
 
 * Audio driver, outputs the audio to a file (non real-time) 
 
23
 * Audio driver, outputs the audio to a file (non real-time)
24
24
 *
25
25
 */
26
26
 
31
31
 
32
32
 
33
33
/** fluid_file_audio_driver_t
34
 
 * 
 
34
 *
35
35
 * This structure should not be accessed directly. Use audio port
36
 
 * functions instead.  
 
36
 * functions instead.
37
37
 */
38
38
typedef struct {
39
39
        fluid_audio_driver_t driver;
70
70
}
71
71
 
72
72
 
73
 
fluid_audio_driver_t* 
 
73
fluid_audio_driver_t*
74
74
new_fluid_file_audio_driver(fluid_settings_t* settings,
75
75
                            fluid_synth_t* synth)
76
76
{
82
82
        dev = FLUID_NEW(fluid_file_audio_driver_t);
83
83
        if (dev == NULL) {
84
84
                FLUID_LOG(FLUID_ERR, "Out of memory");
85
 
                return NULL;    
 
85
                return NULL;
86
86
        }
87
87
        FLUID_MEMSET(dev, 0, sizeof(fluid_file_audio_driver_t));
88
88
 
125
125
int delete_fluid_file_audio_driver(fluid_audio_driver_t* p)
126
126
{
127
127
        fluid_file_audio_driver_t* dev = (fluid_file_audio_driver_t*) p;
128
 
  
 
128
 
129
129
        if (dev == NULL) {
130
130
                return FLUID_OK;
131
131
        }
157
157
static int fluid_file_audio_run_s16(void* d, unsigned int clock_time)
158
158
{
159
159
        fluid_file_audio_driver_t* dev = (fluid_file_audio_driver_t*) d;
160
 
        float* handle[2];
161
 
        int i, k, n, offset;
162
 
        float s;
 
160
        int n, offset;
163
161
        unsigned int sample_time;
164
162
 
165
 
        handle[0] = dev->left;
166
 
        handle[1] = dev->right;
167
 
 
168
 
 
169
163
        sample_time = (unsigned int) (dev->samples / dev->sample_rate * 1000.0);
170
164
        if (sample_time > clock_time) {
171
165
                return 1;
172
166
        }
173
167
 
174
 
        (*dev->callback)(dev->data, dev->period_size, 0, NULL, 2, handle);
175
 
        
176
 
        for (i = 0, k = 0; i < dev->period_size; i++, k += 2) {
177
 
                s = 32768.0f * dev->left[i];
178
 
                fluid_clip(s, -32768.0f, 32767.0f);
179
 
                dev->buf[k] = (short) s;
180
 
        }
181
 
        
182
 
        for (i = 0, k = 1; i < dev->period_size; i++, k += 2) {
183
 
                s = 32768.0f * dev->right[i];
184
 
                fluid_clip(s, -32768.0f, 32767.0f);
185
 
                dev->buf[k] = (short) s;
186
 
        }
187
 
        
 
168
        fluid_synth_write_s16(dev->data, dev->period_size, dev->buf, 0, 2, dev->buf, 1, 2);
 
169
 
188
170
        for (offset = 0; offset < dev->buf_size; offset += n) {
189
 
                
 
171
 
190
172
                n = fwrite((char*) dev->buf + offset, 1, dev->buf_size - offset, dev->file);
191
173
                if (n < 0) {
192
 
                        FLUID_LOG(FLUID_ERR, "Audio file error");
193
 
                        return 0;       
194
 
                } 
 
174
                        FLUID_LOG(FLUID_ERR, "Audio output file write error: %s",
 
175
                                  strerror (errno));
 
176
                        return 0;
 
177
                }
195
178
        }
196
 
        
 
179
 
197
180
        dev->samples += dev->period_size;
198
181
 
199
182
        return 1;
200
 
 
201
 
 error_recovery:
202
 
  
203
 
        return 0;
204
183
}