Mercurial > octave-nkf
comparison libinterp/dldfcn/audioread.cc @ 19578:827394ba8eb2
Backed out changeset 5f313345912f
Undo accidental changes from previous changeset.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 Jan 2015 18:11:05 -0500 |
parents | 5f313345912f |
children | 57efd0a020cf |
comparison
equal
deleted
inserted
replaced
19577:5f313345912f | 19578:827394ba8eb2 |
---|---|
21 */ | 21 */ |
22 | 22 |
23 #ifdef HAVE_CONFIG_H | 23 #ifdef HAVE_CONFIG_H |
24 #include <config.h> | 24 #include <config.h> |
25 #endif | 25 #endif |
26 | |
27 #define BOUNDS_CHECKING 1 | |
28 | 26 |
29 #include <string> | 27 #include <string> |
30 #include <map> | 28 #include <map> |
31 | 29 |
32 #include "oct-locbuf.h" | 30 #include "oct-locbuf.h" |
247 return retval; | 245 return retval; |
248 | 246 |
249 SNDFILE *file; | 247 SNDFILE *file; |
250 SF_INFO info; | 248 SF_INFO info; |
251 | 249 |
252 memset (&info, 0, sizeof (info)); | |
253 | |
254 OCTAVE_LOCAL_BUFFER (float, data, audio.rows () * audio.cols ()); | 250 OCTAVE_LOCAL_BUFFER (float, data, audio.rows () * audio.cols ()); |
255 | 251 |
256 size_t idx = 0; | 252 for (int i = 0; i < audio.cols (); i++) |
257 for (octave_idx_type j = 0; j < audio.rows (); j++) | 253 { |
258 { | 254 for (int j = 0; j < audio.rows (); j++) |
259 for (octave_idx_type i = 0; i < audio.cols (); i++) | 255 data[j * audio.cols () + i] = audio(j, i); |
260 data[idx++] = audio(j, i); | 256 } |
261 } | |
262 | |
263 std::cerr << "idx: " << idx << std::endl; | |
264 | 257 |
265 if (extension == "ogg") | 258 if (extension == "ogg") |
266 info.format = SF_FORMAT_VORBIS; | 259 info.format = SF_FORMAT_VORBIS; |
267 else | 260 else |
268 info.format = SF_FORMAT_PCM_16; | 261 info.format = SF_FORMAT_PCM_16; |
313 | 306 |
314 info.samplerate = args(2).int_value (); | 307 info.samplerate = args(2).int_value (); |
315 info.channels = audio.cols (); | 308 info.channels = audio.cols (); |
316 info.format |= extension_to_format[extension]; | 309 info.format |= extension_to_format[extension]; |
317 | 310 |
318 std::cerr << extension << std::endl; | |
319 std::cerr << extension_to_format[extension] << std::endl; | |
320 std::cerr << info.format << std::endl; | |
321 std::cerr << SF_FORMAT_OGG << std::endl; | |
322 std::cerr << SF_FORMAT_VORBIS << std::endl; | |
323 | |
324 // info.format = SF_FORMAT_OGG; | |
325 | |
326 file = sf_open (filename.c_str (), SFM_WRITE, &info); | 311 file = sf_open (filename.c_str (), SFM_WRITE, &info); |
327 | 312 |
328 if (title != "") | 313 if (title != "") |
329 sf_set_string (file, SF_STR_TITLE, title.c_str ()); | 314 sf_set_string (file, SF_STR_TITLE, title.c_str ()); |
330 | 315 |
332 sf_set_string (file, SF_STR_ARTIST, artist.c_str ()); | 317 sf_set_string (file, SF_STR_ARTIST, artist.c_str ()); |
333 | 318 |
334 if (comment != "") | 319 if (comment != "") |
335 sf_set_string (file, SF_STR_COMMENT, comment.c_str ()); | 320 sf_set_string (file, SF_STR_COMMENT, comment.c_str ()); |
336 | 321 |
337 sf_count_t items_to_write = audio.rows () * audio.cols (); | 322 sf_write_float (file, data, audio.rows () * audio.cols ()); |
338 | |
339 memset (&info, 0, sizeof (info)) ; | |
340 info.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS ; | |
341 info.channels = 2 ; | |
342 info.samplerate = 44100 ; | |
343 | |
344 sf_count_t items_written = sf_write_float (file, data, items_to_write); | |
345 | |
346 sf_close (file); | 323 sf_close (file); |
347 | 324 |
348 if (items_written != items_to_write) | |
349 { | |
350 error ("expected to write %ld items, wrote %ld items", | |
351 items_to_write, items_written); | |
352 return retval; | |
353 } | |
354 | |
355 #else | 325 #else |
356 | 326 |
357 error ("sndfile not found on your system and thus audiowrite is not functional"); | 327 error ("sndfile not found on your system and thus audiowrite is not functional"); |
358 | 328 |
359 #endif | 329 #endif |
386 result.assign ("Filename", args(0).string_value ()); | 356 result.assign ("Filename", args(0).string_value ()); |
387 result.assign ("CompressionMethod", ""); | 357 result.assign ("CompressionMethod", ""); |
388 result.assign ("NumChannels", info.channels); | 358 result.assign ("NumChannels", info.channels); |
389 result.assign ("SampleRate", info.samplerate); | 359 result.assign ("SampleRate", info.samplerate); |
390 result.assign ("TotalSamples", info.frames); | 360 result.assign ("TotalSamples", info.frames); |
391 result.assign ("Format", info.format); | |
392 | 361 |
393 double dframes = info.frames; | 362 double dframes = info.frames; |
394 double drate = info.samplerate; | 363 double drate = info.samplerate; |
395 result.assign ("Duration", dframes / drate); | 364 result.assign ("Duration", dframes / drate); |
396 | 365 |