回复: Incorrect work of sox_open_memstream_write with memstream buffer and buffersize

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



here is a demo:

```

  1. #include "sox.h"
  2. #include "util.h"
  3. #include <stdio.h>
  4. #include <assert.h>
  5. /* Example of reading and writing audio files stored in memory buffers
  6.  * rather than actual files.
  7.  *
  8.  * Usage: example5 input output
  9.  */
  10. int main(int argc, char * argv[])
  11. {
  12.   static sox_format_t * in, * out;
  13.   #define MAX_SAMPLES (size_t)2048
  14.   sox_sample_t samples[MAX_SAMPLES];
  15.   char * buffer;
  16.   size_t buffer_size;
  17.   size_t number_read;
  18.   assert(argc == 3);
  19.   assert(sox_init() == SOX_SUCCESS);
  20.   assert((in = sox_open_read(argv[1], NULLNULLNULL)));
  21.   sox_encodinginfo_t out_encoding = {
  22.     SOX_ENCODING_ULAW,
  23.     8,
  24.     0,
  25.     sox_option_default,
  26.     sox_option_default,
  27.     sox_option_default,
  28.     sox_false
  29.   };
  30.   sox_signalinfo_t out_signal = {
  31.     8000,
  32.     1,
  33.     0,
  34.     0,
  35.     NULL
  36.   };
  37.   assert(out = sox_open_memstream_write(&buffer, &buffer_size, &out_signal, &out_encoding, "wav"NULL));
  38.   while ((number_read = sox_read(in, samples, MAX_SAMPLES)))
  39.     assert(sox_write(out, samples, number_read) == number_read);
  40.   sox_close(out);
  41.   sox_close(in);
  42.   printf("%ld\n", buffer_size);
  43.   free(buffer);
  44.   sox_quit();
  45.   return 0;
  46. }

```

$ ./example5 in.wav out.wav

$ 58


At this line 48: `printf("%ld\n", buffer_size);`
I take it for granted that it should be the length of the whole file,but due to the seek option,I can only get length of wav header.

I know it is feasible to get file data before sox_close through ft.fp, but at some situations I need get data from buff and buffsize.

发件人: Jan Stary <hans@xxxxxxxx>
发送时间: 2021年7月24日 18:43
收件人: sox-users@xxxxxxxxxxxxxxxxxxxxx <sox-users@xxxxxxxxxxxxxxxxxxxxx>
主题: Re: Incorrect work of sox_open_memstream_write with memstream buffer and buffersize
 
On Jul 23 01:43:36, hisunzhenliang@xxxxxxxxxxx wrote:
> Opened by sox_open_memstream_write function,the buffer and buffersize will work incorrectly when seeking back。
>
> For example, when opening buffer with sox_open_memstream_write to get a wav format output,wav handler's  stopwrite function will seek back to the beginning to rewrite wav header. In this situation,after closing ft,I assume that I can get whole data from buff and buffsize,but I can only get the wav header.
>
> I don't think it would be better to have seek back to the end when you need to rewrite data with a seek operation.

Without seeing the actual code,
it's hard to try to help.



_______________________________________________
Sox-users mailing list
Sox-users@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/sox-users
_______________________________________________
Sox-users mailing list
Sox-users@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/sox-users

[Index of Archives]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux