Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 104325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:15:50+00:00 2026-05-11T01:15:50+00:00

I’m looking for a lightweight way to make my program (written in C) be

  • 0

I’m looking for a lightweight way to make my program (written in C) be able to play audio files on either windows or linux. I am currently using windows native calls, which is essentially just a single call that is passed a filename. I would like something similar that works on linux.

The audio files are Microsoft PCM, Single channel, 22Khz

Any Suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:15:50+00:00Added an answer on May 11, 2026 at 1:15 am

    Since I’m also looking for an answer for question I did a bit of research, and I haven’t find any simple (simple like calling one function) way to play an audio file. But with some lines of code, it is possible even in a portable way using the already mentioned portaudio and libsndfile (LGPL).

    Here is a small test case I’ve written to test both libs:

     #include <portaudio.h> #include <sndfile.h>  static int output_cb(const void * input, void * output, unsigned long frames_per_buffer,         const PaStreamCallbackTimeInfo *time_info,         PaStreamCallbackFlags flags, void * data) {     SNDFILE * file = data;      /* this should not actually be done inside of the stream callback      * but in an own working thread       *      * Note although I haven't tested it for stereo I think you have      * to multiply frames_per_buffer with the channel count i.e. 2 for      * stereo */     sf_read_short(file, output, frames_per_buffer);     return paContinue; }  static void end_cb(void * data) {     printf('end!\n'); }  #define error_check(err) \     do {\         if (err) { \             fprintf(stderr, 'line %d ', __LINE__); \             fprintf(stderr, 'error number: %d\n', err); \             fprintf(stderr, '\n\t%s\n\n', Pa_GetErrorText(err)); \             return err; \         } \     } while (0)  int main(int argc, char ** argv) {     PaStreamParameters out_param;     PaStream * stream;     PaError err;     SNDFILE * file;     SF_INFO sfinfo;      if (argc < 2)     {         fprintf(stderr, 'Usage %s \n', argv[0]);         return 1;     }      file = sf_open(argv[1], SFM_READ, &sfinfo);     printf('%d frames %d samplerate %d channels\n', (int)sfinfo.frames,             sfinfo.samplerate, sfinfo.channels);      /* init portaudio */     err = Pa_Initialize();     error_check(err);      /* we are using the default device */     out_param.device = Pa_GetDefaultOutputDevice();     if (out_param.device == paNoDevice)     {         fprintf(stderr, 'Haven't found an audio device!\n');         return -1;     }      /* stero or mono */     out_param.channelCount = sfinfo.channels;     out_param.sampleFormat = paInt16;     out_param.suggestedLatency = Pa_GetDeviceInfo(out_param.device)->defaultLowOutputLatency;     out_param.hostApiSpecificStreamInfo = NULL;      err = Pa_OpenStream(&stream, NULL, &out_param, sfinfo.samplerate,             paFramesPerBufferUnspecified, paClipOff,             output_cb, file);     error_check(err);      err = Pa_SetStreamFinishedCallback(stream, &end_cb);     error_check(err);      err = Pa_StartStream(stream);     error_check(err);      printf('Play for 5 seconds.\n');     Pa_Sleep(5000);      err = Pa_StopStream(stream);     error_check(err);      err = Pa_CloseStream(stream);     error_check(err);      sf_close(file);      Pa_Terminate();      return 0; } 

    Some notes to the example. It is not good practice to do the data loading inside of the stream callback, but inside an own loading thread. If you need to play several audio files it becomes even more difficult, because not all portaudio backends support multiple streams for one device, for example the OSS backend doesn’t, but the ALSA backend does. I don’t know how the situation is on windows. Since all your input files are of the same type you could mix them on you own, which complicates the code a bit more, but then you’d have also support for OSS. If you would have also different sample rates or number of channels, it’d become very difficult.

    So If you don’t want to play multiple files at the same time, this could be a solution or at least a start for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 277k
  • Answers 277k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is related to the "Content-Type" header: the client must… May 13, 2026 at 2:57 pm
  • Editorial Team
    Editorial Team added an answer There is the possibility of a background-image but it's difficult… May 13, 2026 at 2:57 pm
  • Editorial Team
    Editorial Team added an answer You need to set the IsChecked Bindings to Mode=TwoWay, e.g.… May 13, 2026 at 2:57 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.