Thread: Audio player beginning

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    96

    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!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2016
    Posts
    96
    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.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2016
    Posts
    96
    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'|

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Link to the library that provides PlaySoundA@12

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Dec 2016
    Posts
    96
    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
    Last edited by ArakelTheDragon; 03-30-2020 at 02:41 AM.

  8. #8
    Registered User
    Join Date
    Dec 2016
    Posts
    96
    Sorry for the double post.
    Here is the link for .mp3 and other formats. It gives good explanations.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-08-2017, 07:53 PM
  2. Audio Player Thread
    By Lane the Great in forum C Programming
    Replies: 18
    Last Post: 02-02-2011, 05:14 PM
  3. Built simple audio player without gui
    By sauronnikko in forum C++ Programming
    Replies: 6
    Last Post: 02-01-2011, 01:09 AM
  4. Audio player
    By Anuradh_a in forum Windows Programming
    Replies: 2
    Last Post: 04-05-2008, 01:16 PM
  5. is it hard to make a audio player
    By sobbles in forum C++ Programming
    Replies: 5
    Last Post: 10-12-2002, 10:10 AM

Tags for this Thread