Closed tangkk closed 6 years ago
@tangkk, thanks for the suggestion. That looks like the same behavior as setting scale=(-1, 1)
. Have you tried that?
@tangkk, thanks for the suggestion. That looks like the same behavior as setting
scale=(-1, 1)
. Have you tried that?
Yes I believe scale=(-1,1) does the same thing. Thanks for pointing this out since I didn't get it at first: by reading your comments in the "write" function I misunderstood that this is done by setting scale as "none". ("If scale
is the string "none", then vmin
and vmax
are set to
outmin
and outmax
, respectively. This means the data is written
to the file with no scaling.")
But if I need to convert my float array to 16bit PCM with no scaling, what I should use is actually scale=(-1,1) instead of scale="none", this is a bit strange to me at first...
The various scale
options can be confusing. The option scale='none'
means that the floating point input values are converted directly to integers, without any shifting or scaling of the input values. So if the floating point input array is in the range [-1, 1], the converted integer values will be just -1, 0, and 1. For example, the sequence [0.5, 0.75, 1, 0.6, -0.2, -1.0, -0.9, 0.1, 0.3] would be converted to [0, 0, 1, 0, 0, -1, 0, 0, 0].
But if I need to convert my float array to 16bit PCM with no scaling
But it sound like you do want scaling (at least with my interpretation of what "scaling" means). You want to scale up the values from [-1, 1] to the 16 bit integer range [-2**15, 2**15-1]
. To me, "no scaling" means to convert the floating point values directly to integers, so a value such as 14.35 becomes 14.
I'll work on adding another example to the docstring that shows the use of scale=(-1, 1)
(or something similar).
Thanks for your reply. I think the solution you provide is a good one. The issue could be closed now...
But I should pointed out that the "no scaling" may have little usage scenario given that the sampwidth is changed, which means if you change "sampwidth" to something other than the original sampwidth, you will almost always need to scale. And if you'd just like to keep the "volume" of the output unchanged, you'll have to know exactly the range of the original sampwidth (e.g. [-1,1] in my case).
But I should pointed out that the "no scaling" may have little usage scenario
I agree, that option is probably not one that will be used often.
(I edited this comment to remove some comments that were based on a misinterpretation of the desired behavior.)
I found this issue as captioned. Many data to be written are actually floating point data with [-1,1] range. Sometimes when we write them to file we'd like to write them as is and convert them to say 16bit PCM without any normalization.
To solve this we could do something like:
See if you could accept this modification. Thanks!