-
Audio player beginning
Hi to everyone!
First let me thank you for all of your help until now, I managed to solve my problems and am continuing to learn from my mistakes. I would like to start with audio.
I need to build a simple audio player which will play .wav files for now. My idea is simple, the audio file has to be read and sent to the audio processor. I understand that there are different formats because they are just compressed audio, this means I need to de-compress them and send them to the audio processor. Can you please give me some simple C audio .wav example. I need only the most basic parts, because its very hard to figure out the whole code.
Thank you in advance!
-
Which OS?
Which Compiler?
Are you looking to leverage all the goodies that your current platform provides.
PlaySound function (Windows) | Microsoft Docs
Or are you going really low level and picking the file apart a byte at a time.
WAV - Wikipedia
-
Windows 10.
GCC with codeblocks MinGW 17.12.
I am looking for the simplest approach, byte by byte should be the correct one. I don't see why this needs to be so complex sometimes.
-
You make it complicated by trying to do it all yourself, and not making use of established libraries to do all the work for you.
-
To me trying to use these established libraries is far more complex than building it by myself. They make no sense in a lot of the cases. Seeing pages of code is much worst to me than doing it by myself. This is why I try to learn the core first. I consider these things to be unnecessary complex and cluttered. Normally this should be simple, a function which transfers the file to audio MCU or to a buffer for the audio MCU, only 1 function is enough, why is it necessary to build such a long code for nothing? 1 function to decompress the audio file and 1 to send it to the audio MCU.
Here is the first error:
Code:
#include <windows.h>
#include <mmsystem.h> // Necessary for PlaySound ().
#include <iostream>
#include <inttypes.h> // Necessary for format identifiers like %llu, %lld and etc. %llu can be replaced with %I64u.
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h> // For iQuadraticEquation (void).
error:
obj\Release\main.o:main.cpp|| undefined reference to `PlaySoundA@12'|
-
Link to the library that provides PlaySoundA@12
Tim S.
-
It should be one of these is what I found on the internet?
#include <windows.h>
#include <mmsystem.h> // Necessary for PlaySound ().
#include <iostream>
EDIT: OK my mistake, the library is Winmm.dll, its added and the playing of .wav files works correctly.
1. Answer to how to add library: Why dose this not work? - C++ Forum
2. Library download: Download Winmm.dll for Windows 10, 8.1, 8, 7, Vista and XP - 32 Bit and 64 Bit
3. Instructions on adding the library: c++ - How do I link to a library with Code::Blocks? - Stack Overflow
-
Sorry for the double post.
Here is the link for .mp3 and other formats. It gives good explanations.