A simple-to-use sound file writer
Alf P. Steinbach
alfps at start.no
Thu Jan 14 11:26:05 EST 2010
* Peter Otten:
> Alf P. Steinbach wrote:
>
>> Just as a contribution, since someone hinted that I haven't really
>> contributed much to the Python community.
>>
>> The [simple_sound] code will probably go into my ch 3 at <url:
>> http://tinyurl.com/programmingbookP3>, but sans sine wave generation since
>> I haven't yet discussed trig functions, and maybe /with/ changes suggested
>> by you?
>
>> def _append_as_big_endian_int16_to( a, i ):
>> if i < 0:
>> i = i + 65536
>> assert( 0 <= i < 65536 )
>> a.append( i // 256 )
>> a.append( i % 256 )
>
>> data = array.array( "B" ) # B -> unsigned bytes.
>
> Do you know that array.array() supports 16 bit signed integers?
Yes. I used bytes since that seemed to be what [wave] required. But I tested now
and at least [aifc] handles 16-bit integers fine.
Hm, nice example down the drain...
> There's even
> a byteswap() method to deal with endianess.
>
>> Utility class that may be used to capture output (an instance of this or
>> any other file like class can be passed as "filename" to
>> simple_sound.Writer):
>>
>> <code>
>> class BytesCollector:
>
> Are you reinventing io.BytesIO() here?
Probably. :-) Checking... Yes, I was; thanks!
Cheers,
- Alf
More information about the Python-list
mailing list