<?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>PWM Audio driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52878/pwm-audio-driver</link><description>Hello, I just wanted to throw in that for a hobby project I created a PWM audio driver, with which one can play back 8-bit audio data very easily. Since it may be useful for others, too, I have uploaded the sources to https://nrf52-pwm-audio.sourceforge</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 29 Jul 2022 06:37:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52878/pwm-audio-driver" /><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/379233?ContentTypeID=1</link><pubDate>Fri, 29 Jul 2022 06:37:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cca53f6-db62-4e5c-9dc5-8d95ab8d7849</guid><dc:creator>Felix41382</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;have you tried to re-sample your file with ffmpeg as described in my github project:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/don41382/nrf52-pwm-wav-sbc-decoder-player/blob/main/files/decode.sh#L32"&gt;https://github.com/don41382/nrf52-pwm-wav-sbc-decoder-player/blob/main/files/decode.sh#L32&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That worked for me pretty good.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;br /&gt;Felix&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/379202?ContentTypeID=1</link><pubDate>Thu, 28 Jul 2022 21:56:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e082de2-d70e-4e06-a09a-f1b2f217b99b</guid><dc:creator>builder01</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/newtom"&gt;NewtoM&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I had a hand in testing your library. It works pretty well, however, I noticed something strange in the way my melody is played and I wonder if I&amp;#39;m doing something wrong.&lt;/p&gt;
&lt;p&gt;I created a simple melody in LMMS (I&amp;#39;m using ubuntu), and I export it to a .WAV file. Then, I used audacity to trim it and export it to .raw (headerless) and a signed 8-bit PCM. I made sure to also set in preferences the sample rate to one of the supported frequencies you mentioned.&lt;/p&gt;
&lt;p&gt;After this, I use xxd -i to convert it to a .c file. I also create a .h file based on it to include in my main.c file.&lt;/p&gt;
&lt;p&gt;The melody reproduces faithfully, except for the fact that it&amp;#39;s about half the tempo I originally created it for. Could it be something caused by the xxd, some setting in your library I didn&amp;#39;t set properly?&lt;/p&gt;
&lt;p&gt;To initialize it I&amp;#39;m using:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool const pwm_audio_highdrive = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nrf_pwm_audio_init(buzzer_external_pin, pwm_audio_highdrive);&lt;br /&gt;where buzzer_external_pin = 3.&lt;/p&gt;
&lt;p&gt;Thanks in advance if there&amp;#39;s any suggestion&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/343451?ContentTypeID=1</link><pubDate>Tue, 14 Dec 2021 15:19:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26c5b00b-5d86-4173-a075-54a4cb707ab4</guid><dc:creator>Felix41382</dc:creator><description>&lt;p&gt;Hi tamas,&lt;/p&gt;
&lt;p&gt;I read more about MP3 decoding and yes, for MP3 1152 is a fixed frame size for mono. FIFO totally makes sense, but increasing the PWM buffer keeps code simpler.&lt;/p&gt;
&lt;p&gt;Currently I&amp;nbsp;am struggling with&amp;nbsp;&amp;quot;Data Access Violation&amp;quot;. I already tried to change CONFIG_MAIN_STACK_SIZE and&amp;nbsp;CONFIG_HEAP_MEM_POOL_SIZE, but that doesn&amp;#39;t help. Maybe you know&amp;nbsp;a working memory setting or what needs to be tweaked.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;br /&gt;Felix&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/343274?ContentTypeID=1</link><pubDate>Mon, 13 Dec 2021 21:59:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d765aa0d-da2c-443d-be97-a35f81c998a1</guid><dc:creator>NewtoM</dc:creator><description>&lt;p&gt;Hey Felix,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think you&amp;#39;ll be able to change the 1152 samples frame size of minimp3. Either, you change buffer size of PWM, or you&amp;#39;ll need to implement a FIFO between the two modules.&lt;/p&gt;
&lt;p&gt;For the latter, the producer and consumer would be minimp3 and the PWM driver, respectively. Whenever PWM consumes 512 samples and there is less than 512 left in the FIFO, you&amp;#39;d let minimp3 decode the next 1152 samples and add them to the FIFO. If minimp3 decoding happens fast enough, this would work.&lt;/p&gt;
&lt;p&gt;Tamas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/343206?ContentTypeID=1</link><pubDate>Mon, 13 Dec 2021 14:00:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4a9059a-60a1-4d7b-be0c-bfdb4cd7f898</guid><dc:creator>Felix41382</dc:creator><description>&lt;p&gt;Thanks Tamas for the nice trick with the positive Speaker connection. I&amp;#39;ll try this later on. Removing the&amp;nbsp;&lt;span&gt;NRFX_PWM_PIN_INVERTED just enhanced the clicking noise. I am getting an Oscilloscope for Christmas - so I guess seeing is better than hearing.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I just started with including the minimp3 library from lieff, but there is one issue. The `&lt;/span&gt;mp3dec_decode_frame` always returns at least 1152 samples (1 frame). Do you know if I can reduce this? Because the PWM buffers&amp;nbsp;need to be filled by 512 /&amp;nbsp;256 (for 16kHz) or do I have to chunk this by myself?&lt;/p&gt;
&lt;p&gt;Thanks again for your quick support and your nice work on the PWM stuff.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/343012?ContentTypeID=1</link><pubDate>Sat, 11 Dec 2021 17:29:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41dfcfd1-2f9e-4009-9b48-01ce32b83a61</guid><dc:creator>NewtoM</dc:creator><description>&lt;p&gt;Dear Felix,&lt;/p&gt;
&lt;p&gt;I am happy you&amp;#39;ve found the PWM driver and could use it.&lt;/p&gt;
&lt;p&gt;Regarding your question, as far as I remember, I connected the output between Vdd (not Gnd) and the PWM output pin and used the PWM output in an inverted fashion. This gave me better quality and less noise. You could try to change the PWM config and remove inversion (see &lt;a href="https://sourceforge.net/p/nrf52-pwm-audio/code/ci/master/tree/Modules/nrf_pwm_audio.c,"&gt;https://sourceforge.net/p/nrf52-pwm-audio/code/ci/master/tree/Modules/nrf_pwm_audio.c,&lt;/a&gt; Line 221, remove &lt;span class="n"&gt;NRFX_PWM_PIN_INVERTED&lt;/span&gt;&lt;span class="p"&gt;&lt;/span&gt; flag) and see if the click goes away.&lt;/p&gt;
&lt;p&gt;Other than that I can report that I successfully combined the PWM driver with minimp3 (&lt;a href="https://github.com/lieff/minimp3"&gt;https://github.com/lieff/minimp3&lt;/a&gt;) to play back mono (low bitrate) mp3 files in real-time on nRF52840. You may want to include that too among your codecs.&lt;/p&gt;
&lt;p&gt;Best,&lt;br /&gt;Tamas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/343011?ContentTypeID=1</link><pubDate>Sat, 11 Dec 2021 16:25:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5090f071-9535-4e2c-9e86-bcd012f0c7bf</guid><dc:creator>Felix41382</dc:creator><description>&lt;p&gt;Hello Tamas,&lt;/p&gt;
&lt;p&gt;you inspired me to create my own project which&amp;nbsp;supports additional codecs. I started with a sbc decoder implementation.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;PWMPlayer player;
player.init(AUDIO_PIN);

AudioDecoderSbc decoder(sample_itsworking_sbc, sample_itsworking_sbc_size);
player-&amp;gt;play(&amp;amp;decoder, 2.0);
while(player-&amp;gt;isPlaying()) { __WFE(); }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The only problem I have, is the initialisation of the audio PWM pin, which creates a spike (click noise) on calling `nrfx_pwm_init`. Does anyone have an idea how to fix this?&lt;/p&gt;
&lt;p&gt;The project can be found on:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/don41382/nrf52-pwm-wav-sbc-decoder-player"&gt;https://github.com/don41382/nrf52-pwm-wav-sbc-decoder-player&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Felix&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/284014?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 11:00:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78abdea9-5f48-4164-a487-7e405d0a5bfa</guid><dc:creator>Styve Naoue</dc:creator><description>&lt;p&gt;Hello &lt;a href="https://devzone.nordicsemi.com/members/t2uhpph"&gt;MQ_Question&lt;/a&gt; sorry for the late reply. Please browse to&amp;nbsp;&lt;a href="https://sourceforge.net/p/nrf52-pwm-audio/code/ci/master/tree/"&gt;source code&lt;/a&gt;&amp;nbsp;and git clone the repository to your pc. In the cloded folder you would fine the source code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;All the best.&lt;/p&gt;
&lt;p&gt;Styve&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/283943?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 05:54:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:206bcf35-1962-4026-a22d-ce6856d144a5</guid><dc:creator>NewtoM</dc:creator><description>&lt;p&gt;Click download snapshot on this page:&amp;nbsp;&lt;a href="https://sourceforge.net/p/nrf52-pwm-audio/code/"&gt;sourceforge.net/.../&lt;/a&gt; .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/283940?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 03:24:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:034e0df3-95e6-4588-b76c-9827106cd77e</guid><dc:creator>MQ_Question</dc:creator><description>&lt;p&gt;Hi&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/dev_5f00_sport"&gt;Styve Naoue&lt;/a&gt;&lt;br /&gt;I can&amp;#39;t download the code on git -&amp;nbsp;&amp;nbsp;&lt;a href="https://git.code.sf.net/p/nrf52-pwm-audio/code"&gt;git.code.sf.net/.../code&lt;/a&gt; nrf52-pwm-audio-code&lt;br /&gt;How do you download it???&lt;/p&gt;
&lt;p&gt;Can you show me?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/259376?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2020 08:35:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ec25cbb-5aab-4c62-96b5-6cf509ec3c0a</guid><dc:creator>Styve Naoue</dc:creator><description>&lt;p&gt;Awesome, thanks Tamas.&lt;/p&gt;
&lt;p&gt;I used Tamas&amp;#39;s implementation as basis audio playback in my NRF52840 SoC based project and it works like a charm. Simple flexiblel and lightweight. This saved me a lot of time. I used a PAM3804 audio amplifier for prototyping and attenuated the noise using a 22uF cap in parallel with the PWM output pin and GND. This is ok for a 4 Ohm speaker.&amp;nbsp;&lt;br /&gt;NOTE! Powering the PAM8304 with a separate power source is recommended to prevent power surges on the usb port.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/254867?ContentTypeID=1</link><pubDate>Mon, 15 Jun 2020 05:29:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:001b60e7-4ca7-4c05-b0ca-a0e8c63e2573</guid><dc:creator>esonhon</dc:creator><description>&lt;p&gt;Good job, thanks for sharing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Audio driver</title><link>https://devzone.nordicsemi.com/thread/213276?ContentTypeID=1</link><pubDate>Thu, 03 Oct 2019 22:55:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e883068-7352-432a-8713-2ea91b46fe73</guid><dc:creator>NewtoM</dc:creator><description>&lt;p&gt;(This was not a real question.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>