<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>codehop &#187; abstraction</title>
	<atom:link href="https://codehop.com/tag/abstraction/feed/" rel="self" type="application/rss+xml" />
	<link>https://codehop.com</link>
	<description>#code #art #music</description>
	<lastBuildDate>Mon, 23 Apr 2012 18:37:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Making Records</title>
		<link>https://codehop.com/making-records/</link>
		<comments>https://codehop.com/making-records/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 21:00:40 +0000</pubDate>
		<dc:creator><![CDATA[Jacob Joaquin]]></dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[abstraction]]></category>
		<category><![CDATA[data structure]]></category>
		<category><![CDATA[ftable]]></category>
		<category><![CDATA[record]]></category>
		<category><![CDATA[user-defined opcode]]></category>

		<guid isPermaLink="false">http://csound.noisepages.com/?p=176</guid>
		<description><![CDATA[Not of the vinyl variety, but the computer science data structure. Csound comes with a few ways of generating, storing and retrieving data, with function tables being the primary data structure. Data can also be placed into global variables and &#8230; <a href="https://codehop.com/making-records/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Not of the vinyl variety, but the computer science <a href="http://en.wikipedia.org/wiki/Data_structure">data structure</a>.</p>
<p>Csound comes with a few ways of generating, storing and retrieving data, with function tables being the primary data structure. Data can also be placed into global variables and chn busses. In terms of data <a href="http://en.wikipedia.org/wiki/Abstraction_(computer_science)">abstractions</a>, there isn&#8217;t a whole lot of choice. However, custom data abstractions and structures can be built from within a Csound orchestra.</p>
<p>In my blog <a href="http://csound.noisepages.com/2009/12/simple-keys-modularized-key-mapping/">Simple Keys &#8212; Modularized Key Mapping</a>, I toyed with storing multiple key bindings, frequencies, amplitudes and function table numbers within a single ftable by treating the ftable as if it were an array of <a href="http://en.wikipedia.org/wiki/Record_(computer_science)">records</a>, albeit a fairly clumsy one. Over the weekend, I continued along this line and distilled it even further.</p>
<p><strong>Download:</strong> <a href="http://www.thumbuki.com/TheCsoundBlog/simple_record.csd">simple_record.csd</a></p>
<p>So far, I&#8217;m very happy with the results. Though the implementation maybe a bit hackish, the user-interface isn&#8217;t bad. This new system of making records is composed of five user-defined opcodes: <em>RecordType</em>, <em>RecordField</em>, <em>Record</em>, <em>RecordSet</em> and <em>RecordGet</em>. I additionally wrote wrapper GEN instruments, so they could be accessed from the score.</p>
<p>The first two, <em>RecordType</em> and <em>RecordField</em>, are used to create record abstractions. <em>RecordType</em> creates a new record type, while <em>RecordField</em> appends data fields to the record type. A record type is built from an ftable, thus shares the function table number space. The following score snippet creates a record type as ftable 100, and appends three fields: amp, freq and ftable.</p>
<pre>i $RecordType  0 1 100           ; Record type stored at fn 100
i $RecordField 0 1 100 "amp"     ; Append field "amp"
i $RecordField 0 1 100 "freq"    ; Append field "freq"
i $RecordField 0 1 100 "ftable"  ; Append field "ftable"</pre>
<p>For a record type to be useful, an instance of it must be created with <em>Record</em>. A record is also an ftable, and requires its own unique function table index. The following line creates a record from record type 100, and stores it in ftable 200:</p>
<pre>i $Record 0 1 200 100  ; Instantiate record 200 from type 100</pre>
<p>Once a record is created, the values of each field can be set with <em>RecordSet</em>:</p>
<pre>i $RecordSet 0 1 200 "amp"    0.5  ; Set field "amp"
i $RecordSet 0 1 200 "freq"   440  ; Set field "freq"
i $RecordSet 0 1 200 "ftable" 1    ; Set field "ftable"</pre>
<p>That&#8217;s just one record created from a single record type. In the <a href="http://www.thumbuki.com/TheCsoundBlog/simple_record.csd">csd</a>, you&#8217;ll see I create two more records from the same record type.</p>
<h4>Example</h4>
<p>The Synth instrument is provided to show a simple example on how to use a record. Instead of passing amplitude, frequency and the function number of a stored single cycle wave as pfield data, a record number is passed to Synth with pfield 4. The user-defined opcode <em>RecordGet</em> is used to pull data from the record. The data is then passed to <em>oscil</em>.</p>
<pre>instr $Synth
    irecord = p4  ; Record function number</pre>
<pre>    iamp RecordGet "amp", irecord        ; Get amplitude from record
    ifreq RecordGet "freq", irecord      ; Get frequency from record
    iftable RecordGet "ftable", irecord  ; Get ftable from record</pre>
<pre>    a1 oscil iamp, ifreq, iftable, -1
    out a1
endin</pre>
<pre>...</pre>
<pre>i $Synth 0 1 200  ; Feed synth record 200</pre>
<p>More on all of this later.</p>
]]></content:encoded>
			<wfw:commentRss>https://codehop.com/making-records/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
