<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://pzwiki.wdka.nl/mw-mediadesign/index.php?action=history&amp;feed=atom&amp;title=20131017%EF%BC%9Araw_sound%2Fimage</id>
	<title>20131017：raw sound/image - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://pzwiki.wdka.nl/mw-mediadesign/index.php?action=history&amp;feed=atom&amp;title=20131017%EF%BC%9Araw_sound%2Fimage"/>
	<link rel="alternate" type="text/html" href="https://pzwiki.wdka.nl/mw-mediadesign/index.php?title=20131017%EF%BC%9Araw_sound/image&amp;action=history"/>
	<updated>2026-08-03T13:33:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>https://pzwiki.wdka.nl/mw-mediadesign/index.php?title=20131017%EF%BC%9Araw_sound/image&amp;diff=52082&amp;oldid=prev</id>
		<title>Chen Junyu: /* Raw media */</title>
		<link rel="alternate" type="text/html" href="https://pzwiki.wdka.nl/mw-mediadesign/index.php?title=20131017%EF%BC%9Araw_sound/image&amp;diff=52082&amp;oldid=prev"/>
		<updated>2013-10-14T11:15:14Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Raw media&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:15, 14 October 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l11&quot;&gt;Line 11:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 11:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Raw media ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Raw media ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can use python to generate the &amp;quot;raw&amp;quot; bits of say an audio waveform or a bitmap image. Certain formats, such as audio WAV files or bitmap formats like TGA and BMP (when uncompressed) are easy to generate and manipulate with generic tools like python because the formats are often mostly &amp;quot;raw&amp;quot; sample or pixel data with a short preceding &amp;quot;header&amp;quot; that declares some key properties about the file (such as sampling rate, or image size).&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can use python to generate the &amp;quot;raw&amp;quot; bits of say an audio waveform or a bitmap image. Certain formats, such as audio WAV files or bitmap formats like TGA and BMP (when uncompressed) are easy to generate and manipulate with generic tools like python because the formats are often mostly &amp;quot;raw&amp;quot; sample or pixel data with a short preceding &amp;quot;header&amp;quot; that declares some key properties about the file (such as sampling rate, or image size).&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;python可以生成未加工的电子波形（声音）或者位图（bitmap image：TGA &amp;amp;BMP）&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==generate sound by python ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==generate sound by python ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Chen Junyu</name></author>
	</entry>
	<entry>
		<id>https://pzwiki.wdka.nl/mw-mediadesign/index.php?title=20131017%EF%BC%9Araw_sound/image&amp;diff=52076&amp;oldid=prev</id>
		<title>Chen Junyu: Created page with &quot;== BIT ==  binary 二进制的，二元的 digit 数字  Binary digit bit is general tool of python to open files，count...   == Bit shift ==  The simple act of opening an au...&quot;</title>
		<link rel="alternate" type="text/html" href="https://pzwiki.wdka.nl/mw-mediadesign/index.php?title=20131017%EF%BC%9Araw_sound/image&amp;diff=52076&amp;oldid=prev"/>
		<updated>2013-10-14T11:07:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== BIT ==  binary 二进制的，二元的 digit 数字  Binary digit bit is general tool of python to open files，count...   == Bit shift ==  The simple act of opening an au...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== BIT ==&lt;br /&gt;
 binary 二进制的，二元的 digit 数字&lt;br /&gt;
 Binary digit bit is general tool of python to open files，count...&lt;br /&gt;
 &lt;br /&gt;
== Bit shift ==&lt;br /&gt;
&lt;br /&gt;
The simple act of opening an audio file in a text editor (or the reverse of opening a text as a digital audio) raises many questions. What exactly '''is''' a digital representation of a text, or a sound. The fact that once digital, bits can be as easily interpreted as text or as sound, or image, or other kind of data is at once fascinating, but also deceptively reinforces an idea of multimedia as inherantly bridging and mixing together media. Media formats, and their underlying digital representations, are highly specialized codes (algorithmic, legal) involved in the related processes of encoding and decoding.&lt;br /&gt;
&lt;br /&gt;
A bit shift is the process by which the bits of some data value are shifted in position either &amp;quot;left&amp;quot; or &amp;quot;right&amp;quot; (that is away from or towards the &amp;quot;least significant&amp;quot; bit position). In a simple numerical representation of integers such a shift corresponds to multiplication and division by a power of two. This as a result of the design and working of the system of binary representation, with each column defined to represent powers of 2. The same operation performed on the characters of a text represented as ASCII code values would produce a much different result as the system of representation is structured very differently (with groupings of characters organized not so much by numeric relations, but by clusters of associated symbols and the conventions of the alphabet).&lt;br /&gt;
&lt;br /&gt;
== Raw media ==&lt;br /&gt;
We can use python to generate the &amp;quot;raw&amp;quot; bits of say an audio waveform or a bitmap image. Certain formats, such as audio WAV files or bitmap formats like TGA and BMP (when uncompressed) are easy to generate and manipulate with generic tools like python because the formats are often mostly &amp;quot;raw&amp;quot; sample or pixel data with a short preceding &amp;quot;header&amp;quot; that declares some key properties about the file (such as sampling rate, or image size).&lt;br /&gt;
&lt;br /&gt;
==generate sound by python ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import wave, struct&lt;br /&gt;
&lt;br /&gt;
filename = &amp;quot;output.wav&amp;quot;&lt;br /&gt;
nframes=0&lt;br /&gt;
nchannels=1&lt;br /&gt;
sampwidth=2 # in bytes so 2=16bit, 1=8bit&lt;br /&gt;
framerate=44100&lt;br /&gt;
bufsize=2048&lt;br /&gt;
&lt;br /&gt;
w = wave.open(filename, 'w')&lt;br /&gt;
w.setparams((nchannels, sampwidth, framerate, nframes, 'NONE', 'not compressed'))&lt;br /&gt;
&lt;br /&gt;
max_amplitude = float(int((2 ** (sampwidth * 8)) / 2) - 1)&lt;br /&gt;
&lt;br /&gt;
# split the samples into chunks (to reduce memory consumption and improve performance)&lt;br /&gt;
#for chunk in grouper(bufsize, samples):&lt;br /&gt;
#    frames = ''.join(''.join(struct.pack('h', int(max_amplitude * sample)) for sample in channels) for channels in chunk if channels is not None)&lt;br /&gt;
#    w.writeframesraw(frames)&lt;br /&gt;
&lt;br /&gt;
freq = 440&lt;br /&gt;
# this means that FREQ times a second, we need to complete a cycle&lt;br /&gt;
# there are FRAMERATE samples per second&lt;br /&gt;
# so FRAMERATE / FREQ = CYCLE LENGTH&lt;br /&gt;
cycle = framerate / freq&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
data = ''&lt;br /&gt;
for i in range(10): #正负波重复的次数&lt;br /&gt;
    for x in range(100):&lt;br /&gt;
        data += struct.pack('h', int(0.5 * max_amplitude))&lt;br /&gt;
    for x in range(100):&lt;br /&gt;
        data += struct.pack('h', int(-0.5 * max_amplitude))&lt;br /&gt;
&lt;br /&gt;
w.writeframesraw(data)&lt;br /&gt;
&lt;br /&gt;
w.close()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Generating &amp;quot;Raw&amp;quot; Images ==&lt;br /&gt;
{{:Raw image}}&lt;/div&gt;</summary>
		<author><name>Chen Junyu</name></author>
	</entry>
</feed>