annotate src/libsndfile-1.0.27/programs/sndfile-play-beos.cpp @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2001 Marcus Overhagen <marcus@overhagen.de>
Chris@40 3 **
Chris@40 4 ** This program is free software; you can redistribute it and/or modify
Chris@40 5 ** it under the terms of the GNU General Public License as published by
Chris@40 6 ** the Free Software Foundation; either version 2 of the License, or
Chris@40 7 ** (at your option) any later version.
Chris@40 8 **
Chris@40 9 ** This program is distributed in the hope that it will be useful,
Chris@40 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@40 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@40 12 ** GNU General Public License for more details.
Chris@40 13 **
Chris@40 14 ** You should have received a copy of the GNU General Public License
Chris@40 15 ** along with this program; if not, write to the Free Software
Chris@40 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@40 17 */
Chris@40 18
Chris@40 19 #include <stdio.h>
Chris@40 20
Chris@40 21 #include <Application.h>
Chris@40 22 #include <SoundPlayer.h>
Chris@40 23 #include <string.h>
Chris@40 24
Chris@40 25 #include <sndfile.h>
Chris@40 26
Chris@40 27 #define BUFFER_LEN 1024
Chris@40 28
Chris@40 29 /*------------------------------------------------------------------------------
Chris@40 30 ** BeOS functions for playing a sound.
Chris@40 31 */
Chris@40 32
Chris@40 33 #if defined (__BEOS__)
Chris@40 34
Chris@40 35 struct shared_data
Chris@40 36 {
Chris@40 37 BSoundPlayer *player;
Chris@40 38 SNDFILE *sndfile;
Chris@40 39 SF_INFO sfinfo;
Chris@40 40 sem_id finished;
Chris@40 41 };
Chris@40 42
Chris@40 43 static void
Chris@40 44 buffer_callback(void *theCookie, void *buf, size_t size, const media_raw_audio_format &format)
Chris@40 45 {
Chris@40 46 shared_data *data = (shared_data *)theCookie;
Chris@40 47 short *buffer = (short *)buf;
Chris@40 48 int count = size / sizeof(short);
Chris@40 49 int m, readcount;
Chris@40 50
Chris@40 51 if (!data->player->HasData())
Chris@40 52 return;
Chris@40 53
Chris@40 54 readcount = sf_read_short(data->sndfile, buffer, count);
Chris@40 55 if (readcount == 0)
Chris@40 56 { data->player->SetHasData(false);
Chris@40 57 release_sem(data->finished);
Chris@40 58 }
Chris@40 59 if (readcount < count)
Chris@40 60 { for (m = readcount ; m < count ; m++)
Chris@40 61 buffer [m] = 0 ;
Chris@40 62 }
Chris@40 63 if (data->sfinfo.pcmbitwidth < 16)
Chris@40 64 { for (m = 0 ; m < count ; m++)
Chris@40 65 buffer [m] *= 256 ;
Chris@40 66 }
Chris@40 67 }
Chris@40 68
Chris@40 69 static void
Chris@40 70 beos_play (int argc, char *argv [])
Chris@40 71 {
Chris@40 72 shared_data data;
Chris@40 73 status_t status;
Chris@40 74 int k;
Chris@40 75
Chris@40 76 /* BSoundPlayer requires a BApplication object */
Chris@40 77 BApplication app("application/x-vnd.MarcusOverhagen-sfplay");
Chris@40 78
Chris@40 79 for (k = 1 ; k < argc ; k++)
Chris@40 80 { printf ("Playing %s\n", argv [k]) ;
Chris@40 81 if (! (data.sndfile = sf_open_read (argv [k], &data.sfinfo)))
Chris@40 82 { sf_perror (NULL) ;
Chris@40 83 continue ;
Chris@40 84 } ;
Chris@40 85
Chris@40 86 if (data.sfinfo.channels < 1 || data.sfinfo.channels > 2)
Chris@40 87 { printf ("Error : channels = %d.\n", data.sfinfo.channels) ;
Chris@40 88 sf_close (data.sndfile) ;
Chris@40 89 continue ;
Chris@40 90 } ;
Chris@40 91
Chris@40 92 data.finished = create_sem(0,"finished");
Chris@40 93
Chris@40 94 media_raw_audio_format format =
Chris@40 95 { data.sfinfo.samplerate,
Chris@40 96 data.sfinfo.channels,
Chris@40 97 media_raw_audio_format::B_AUDIO_SHORT,
Chris@40 98 B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN,
Chris@40 99 BUFFER_LEN * sizeof(short)
Chris@40 100 };
Chris@40 101
Chris@40 102 BSoundPlayer player(&format,"player",buffer_callback,NULL,&data);
Chris@40 103 data.player = &player;
Chris@40 104
Chris@40 105 if ((status = player.InitCheck()) != B_OK)
Chris@40 106 {
Chris@40 107 printf ("Error : BSoundPlayer init failed, %s.\n", strerror(status)) ;
Chris@40 108 delete_sem(data.finished);
Chris@40 109 sf_close (data.sndfile) ;
Chris@40 110 continue ;
Chris@40 111 }
Chris@40 112
Chris@40 113 player.SetVolume(1.0);
Chris@40 114 player.Start();
Chris@40 115 player.SetHasData(true);
Chris@40 116 acquire_sem(data.finished);
Chris@40 117 player.Stop();
Chris@40 118 delete_sem(data.finished);
Chris@40 119
Chris@40 120 sf_close (data.sndfile) ;
Chris@40 121
Chris@40 122 } ;
Chris@40 123
Chris@40 124 } /* beos_play */
Chris@40 125
Chris@40 126 #endif
Chris@40 127
Chris@40 128 /*==============================================================================
Chris@40 129 ** Main function.
Chris@40 130 */
Chris@40 131
Chris@40 132 int
Chris@40 133 main (int argc, char *argv [])
Chris@40 134 {
Chris@40 135 if (argc < 2)
Chris@40 136 { printf ("Usage : %s <input sound file>\n\n", argv [0]) ;
Chris@40 137 return 1 ;
Chris@40 138 } ;
Chris@40 139
Chris@40 140 beos_play (argc, argv) ;
Chris@40 141
Chris@40 142 return 0 ;
Chris@40 143 } /* main */
Chris@40 144