<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HOW TO CONVERT SGTL5000 DATA INTO WAV FILE?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/72850/how-to-convert-sgtl5000-data-into-wav-file</link><description>Hello Team, 
 
 First Thanks to all Nordic support:) 
 My problem : 
 I have interfaced SGTL5000 with Nrf52832 (used SDK 16) I&amp;#39;m getting the audio data on aux connector and also getting data in form of integer value ( negative and positive values ) 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 08 Apr 2021 15:31:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/72850/how-to-convert-sgtl5000-data-into-wav-file" /><item><title>RE: HOW TO CONVERT SGTL5000 DATA INTO WAV FILE?</title><link>https://devzone.nordicsemi.com/thread/303841?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 15:31:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce1ccf9e-24c6-495f-94cb-44fb835ead40</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hard to say for me by just looking at your code if this is correct or not. Did you test it together with the device? Did you encounter any issues?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HOW TO CONVERT SGTL5000 DATA INTO WAV FILE?</title><link>https://devzone.nordicsemi.com/thread/302210?ContentTypeID=1</link><pubDate>Fri, 26 Mar 2021 17:10:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c381bb86-1784-45cd-8dfe-e892a3a6dedf</guid><dc:creator>Dipak</dc:creator><description>&lt;p&gt;HellO,&lt;/p&gt;
&lt;p&gt;Thanks for the reply!&lt;/p&gt;
&lt;p&gt;Here is the my I2S setting .&lt;/p&gt;
&lt;p&gt;//@@@@@@&amp;nbsp; &amp;nbsp;&lt;span&gt;I2S setting&amp;nbsp;&amp;nbsp;&lt;/span&gt;@@@@@@@@@@@@@@@@@@@&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;#define AUDIO_FRAME_WORDS 320&lt;/strong&gt;&lt;br /&gt;#define I2S_BUFFER_SIZE_WORDS AUDIO_FRAME_WORDS * 2 // Double buffered - I2S lib will switch between using first and second half&lt;br /&gt;static uint32_t m_i2s_tx_buffer[I2S_BUFFER_SIZE_WORDS];&lt;br /&gt;static uint32_t m_i2s_rx_buffer[I2S_BUFFER_SIZE_WORDS];&lt;br /&gt; &lt;br /&gt;/* Include car sample to demonstrate that sample can be played from application as well */&lt;br /&gt;#define SAMPLE_LEN 67200&lt;br /&gt;extern const uint8_t car_sample[SAMPLE_LEN];&lt;br /&gt;static uint8_t * p_sample = (uint8_t *)car_sample;&lt;br /&gt;static uint32_t sample_idx = 0;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;strong&gt;int16_t data_audio[(AUDIO_FRAME_WORDS/2)];&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;//@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;/p&gt;
&lt;p&gt;//@@@@@@@@@@@@@@ i2c event handler @@@@@@@@@@@@@@@@@&lt;/p&gt;
&lt;p&gt;static bool i2s_sgtl5000_driver_evt_handler(drv_sgtl5000_evt_t * p_evt)&lt;br /&gt;{&lt;br /&gt; bool ret = false;&lt;br /&gt; //NRF_LOG_INFO(&amp;quot;i2s_sgtl5000_driver_evt_handler %d&amp;quot;, p_evt-&amp;gt;evt);&lt;br /&gt; &lt;br /&gt; //NRF_LOG_INFO(&amp;quot;%d&amp;quot;,p_evt-&amp;gt;param.rx_buf_received.p_data_received);&lt;br /&gt; switch (p_evt-&amp;gt;evt)&lt;br /&gt; {&lt;br /&gt; case DRV_SGTL5000_EVT_I2S_RX_BUF_RECEIVED:&lt;br /&gt; {&lt;/p&gt;
&lt;p&gt;uint16_t * p_buffer = (uint16_t *) p_evt-&amp;gt;param.rx_buf_received.p_data_received;&lt;br /&gt; i2s_buffer_size_words = p_evt-&amp;gt;param.rx_buf_received.number_of_words;&lt;br /&gt; int16_t pcm_stream[i2s_buffer_size_words]; // int16_t - i2s_buffer_size_words size; means we only cover half of data_to_send_buffer, which is fine since we are only using LEFT channel &lt;br /&gt; &lt;br /&gt; memcpy(data_audio, p_buffer, i2s_buffer_size_words); &lt;br /&gt; &lt;br /&gt; ret = true;&lt;br /&gt; }&lt;br /&gt; break;&lt;br /&gt; case DRV_SGTL5000_EVT_I2S_TX_BUF_REQ:&lt;br /&gt; {&lt;br /&gt; //NRF_LOG_INFO(&amp;quot;i2s_sgtl5000_driver_evt_handler TX BUF REQ&amp;quot;);&lt;br /&gt; &lt;br /&gt; /* Play sample! 16kHz sample played on 32kHz frequency! If frequency is changed, this approach needs to change. */&lt;br /&gt; /* Playback of this 16kHz sample depends on I2S MCK, RATIO, Alignment, format, and channels! Needs to be DIV8, RATIO 128X, alignment LEFT, format I2S, channels LEFT. */&lt;br /&gt; &lt;br /&gt; uint16_t * p_buffer = (uint16_t *) p_evt-&amp;gt;param.tx_buf_req.p_data_to_send;&lt;br /&gt; uint32_t i2s_buffer_size_words = p_evt-&amp;gt;param.rx_buf_received.number_of_words;&lt;br /&gt; int16_t pcm_stream[i2s_buffer_size_words]; // int16_t - i2s_buffer_size_words size; means we only cover half of data_to_send_buffer, which is fine since we are only using LEFT channel&lt;br /&gt; &lt;br /&gt; /* Clear pcm buffer */&lt;br /&gt; memset(pcm_stream, 0, sizeof(pcm_stream));&lt;/p&gt;
&lt;p&gt;/* Check if playing the next part of the sample will exceed the sample size, if not, copy over part of sample to be played */&lt;br /&gt; if (sample_idx &amp;lt; SAMPLE_LEN)&lt;br /&gt; {&lt;br /&gt; /* Copy sample bytes into pcm_stream (or remaining part of sample). This should fill up half the actual I2S transmit buffer. */&lt;br /&gt; /* We only want half becuase the sample is a 16kHz sample, and we are running the SGTL500 at 32kHz; see DRV_SGTL5000_FS_31250HZ */&lt;br /&gt; uint32_t bytes_to_copy = ((sample_idx + sizeof(pcm_stream)) &amp;lt; SAMPLE_LEN) ? sizeof(pcm_stream) : SAMPLE_LEN - sample_idx - 1;&lt;br /&gt; memcpy(pcm_stream, &amp;amp;p_sample[sample_idx], bytes_to_copy);&lt;br /&gt; sample_idx += bytes_to_copy;&lt;br /&gt; ret = true;&lt;br /&gt; }&lt;br /&gt; else &lt;br /&gt; {&lt;br /&gt; /* End of buffer reached. */&lt;br /&gt; sample_idx = 0;&lt;br /&gt; ret = false;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; /* Upsample the decompressed audio */&lt;br /&gt; /* i &amp;lt; i2s_buffer_size_words * 2 because we have a uint16_t buffer pointer */&lt;br /&gt; for (int i = 0, pcm_stream_idx = 0; i &amp;lt; i2s_buffer_size_words * 2; i += 2)&lt;br /&gt; {&lt;br /&gt; for (int j = i; j &amp;lt; (i + 2); ++j)&lt;br /&gt; {&lt;br /&gt; p_buffer[j] = pcm_stream[pcm_stream_idx];&lt;/p&gt;
&lt;p&gt;}&lt;br /&gt; ++pcm_stream_idx;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; }&lt;br /&gt; break;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;return ret;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;//@@@@@@@@@@@@@@ Here I am logging the my audio data @@@@@@@@@@@&lt;/p&gt;
&lt;p&gt;// Enter main loop.&lt;br /&gt;for (;;)&lt;br /&gt; {&lt;br /&gt; idle_state_handle();&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; &lt;br /&gt; for(int i = 0; i &amp;lt; (AUDIO_FRAME_WORDS / 2) ; i++)&lt;br /&gt; {&lt;br /&gt; NRF_LOG_RAW_INFO(&amp;quot;%d\n,&amp;quot;,data_audio[i]); &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; NRF_LOG_FLUSH();&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;}//FOR LOOP CLOSED BRACKET&lt;br /&gt; }//MAIN LOOP CLOSED BRACKET&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Please let me know the right settings for getting audio data.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HOW TO CONVERT SGTL5000 DATA INTO WAV FILE?</title><link>https://devzone.nordicsemi.com/thread/301699?ContentTypeID=1</link><pubDate>Wed, 24 Mar 2021 13:55:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0208e9e-2939-4d81-91e0-1fba91ead9c2</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I spoke with our developers that made the Python script to convert the WAV file to C in the GitHub repository. They recommend using the built in&amp;nbsp;package &amp;quot;wave&amp;quot; in Python to convert from PCM array to WAV, for instance like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="python"&gt;import wave

# Raw uint8 values
pcm = [0x01, 0x02, etc.]

# Assume 1 channel, 16-bits (2 bytes), 16 kHz 
# w = open(&amp;quot;my_file.wav&amp;quot;, &amp;quot;wb&amp;quot;)
w.setparams((1, 2, 16000, len(pcm)/2, &amp;#39;NONE&amp;#39;, &amp;#39;not compressed&amp;#39;))
w.writeframes(bytes(pcm))
w.close()&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This should likely work with the endianness used by&amp;nbsp;nRF52 without any explicit&amp;nbsp;converting, but if not, you just needs to re-arrange the bytes in the pcm-array:&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;pcm = [0x01, 0x02, 0x03, 0x04]&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;to:&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;pcm = [0x02, 0x01, 0x04, 0x03]&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Best regards,&lt;br /&gt;Jørgen&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HOW TO CONVERT SGTL5000 DATA INTO WAV FILE?</title><link>https://devzone.nordicsemi.com/thread/301008?ContentTypeID=1</link><pubDate>Fri, 19 Mar 2021 16:59:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6522bdfa-1c9e-4bef-9af5-35169c5b6329</guid><dc:creator>Dipak</dc:creator><description>&lt;p&gt;If this file format is not right then please let me know how to generate the right file format for &lt;strong&gt;.wav&lt;/strong&gt; file&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HOW TO CONVERT SGTL5000 DATA INTO WAV FILE?</title><link>https://devzone.nordicsemi.com/thread/301006?ContentTypeID=1</link><pubDate>Fri, 19 Mar 2021 16:55:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b539e7e8-e538-42aa-a27f-3a32d1a2c80d</guid><dc:creator>Dipak</dc:creator><description>&lt;p&gt;&lt;a href="https://drive.google.com/drive/folders/1Ql2ESePjcKGEIsD5IySIavImhO1Mqe2j?usp=sharing"&gt;drive.google.com/.../1Ql2ESePjcKGEIsD5IySIavImhO1Mqe2j&lt;/a&gt;Thanks for the reply!&lt;/p&gt;
&lt;p&gt;Actually, I already used this example in my customize code but I don&amp;#39;t know how to convert integer data into a&amp;nbsp;&lt;strong&gt;.wav&lt;/strong&gt; file&lt;/p&gt;
&lt;p&gt;I have spent lots of time behind this but still, I have not got success!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have attached the recorded data file please let me know if is it the right file for &lt;strong&gt;.wav&lt;/strong&gt; conversion or not?&lt;/p&gt;
&lt;p&gt;Please help me out with this&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HOW TO CONVERT SGTL5000 DATA INTO WAV FILE?</title><link>https://devzone.nordicsemi.com/thread/300238?ContentTypeID=1</link><pubDate>Tue, 16 Mar 2021 20:45:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f56d262d-5494-49ae-af9e-85aa97814db3</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/NordicPlayground/nRF52-teensy-sgtl5000-audio"&gt;This repository&lt;/a&gt; may provide some useful tips and links.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not aware of any specific libraries for converting to WAV format, but as far as I can see, the input from&amp;nbsp;&lt;span&gt;SGTL5000&amp;nbsp;is PCM format, so any PCM to WAV converters should do the job.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>