* Incorrect work of sox_open_memstream_write with memstream buffer and buffersize
@ 2021-07-23 1:43 Sun Zhenliang
2021-07-24 10:43 ` Jan Stary
0 siblings, 1 reply; 3+ messages in thread
From: Sun Zhenliang @ 2021-07-23 1:43 UTC (permalink / raw)
To: sox-users@lists.sourceforge.net
[-- Attachment #1.1: Type: text/plain, Size: 551 bytes --]
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.
[-- Attachment #1.2: Type: text/html, Size: 1934 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
[-- Attachment #3: Type: text/plain, Size: 158 bytes --]
_______________________________________________
Sox-users mailing list
Sox-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Incorrect work of sox_open_memstream_write with memstream buffer and buffersize
2021-07-23 1:43 Incorrect work of sox_open_memstream_write with memstream buffer and buffersize Sun Zhenliang
@ 2021-07-24 10:43 ` Jan Stary
2021-07-26 2:09 ` 回复: " Sun Zhenliang
0 siblings, 1 reply; 3+ messages in thread
From: Jan Stary @ 2021-07-24 10:43 UTC (permalink / raw)
To: sox-users
On Jul 23 01:43:36, hisunzhenliang@outlook.com 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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users
^ permalink raw reply [flat|nested] 3+ messages in thread
* 回复: Incorrect work of sox_open_memstream_write with memstream buffer and buffersize
2021-07-24 10:43 ` Jan Stary
@ 2021-07-26 2:09 ` Sun Zhenliang
0 siblings, 0 replies; 3+ messages in thread
From: Sun Zhenliang @ 2021-07-26 2:09 UTC (permalink / raw)
To: sox-users@lists.sourceforge.net
[-- Attachment #1.1: Type: text/plain, Size: 3013 bytes --]
here is a demo:
```
1. #include "sox.h"
2. #include "util.h"
3. #include <stdio.h>
4. #include <assert.h>
5.
6. /* Example of reading and writing audio files stored in memory buffers
7. * rather than actual files.
8. *
9. * Usage: example5 input output
10. */
11.
12.
13. int main(int argc, char * argv[])
14. {
15. static sox_format_t * in, * out;
16. #define MAX_SAMPLES (size_t)2048
17. sox_sample_t samples[MAX_SAMPLES];
18. char * buffer;
19. size_t buffer_size;
20. size_t number_read;
21.
22. assert(argc == 3);
23.
24. assert(sox_init() == SOX_SUCCESS);
25. assert((in = sox_open_read(argv[1], NULL, NULL, NULL)));
26. sox_encodinginfo_t out_encoding = {
27. SOX_ENCODING_ULAW,
28. 8,
29. 0,
30. sox_option_default,
31. sox_option_default,
32. sox_option_default,
33. sox_false
34. };
35. sox_signalinfo_t out_signal = {
36. 8000,
37. 1,
38. 0,
39. 0,
40. NULL
41. };
42. assert(out = sox_open_memstream_write(&buffer, &buffer_size, &out_signal, &out_encoding, "wav", NULL));
43. while ((number_read = sox_read(in, samples, MAX_SAMPLES)))
44. assert(sox_write(out, samples, number_read) == number_read);
45. sox_close(out);
46. sox_close(in);
47.
48. printf("%ld\n", buffer_size);
49.
50. free(buffer);
51. sox_quit();
52. return 0;
53. }
```
$ ./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@stare.cz>
发送时间: 2021年7月24日 18:43
收件人: sox-users@lists.sourceforge.net <sox-users@lists.sourceforge.net>
主题: Re: [SoX-users] Incorrect work of sox_open_memstream_write with memstream buffer and buffersize
On Jul 23 01:43:36, hisunzhenliang@outlook.com 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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users
[-- Attachment #1.2: Type: text/html, Size: 25999 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
[-- Attachment #3: Type: text/plain, Size: 158 bytes --]
_______________________________________________
Sox-users mailing list
Sox-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-26 2:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23 1:43 Incorrect work of sox_open_memstream_write with memstream buffer and buffersize Sun Zhenliang
2021-07-24 10:43 ` Jan Stary
2021-07-26 2:09 ` 回复: " Sun Zhenliang
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/sox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).