-
I don't know if this is a bug or if it's caused by me doing something wrong with C. I don't want to pollute the discussion with basic C issues, so If it is on my side, please let me know and I'll figure it out. This is on macOS. The Issue: The program: How to reproduce the issue:
Working Source #define MA_DEBUG_OUTPUT
#define MINIAUDIO_IMPLEMENTATION
#include "../../../miniaudio/miniaudio.h"
#include <stdio.h>
static ma_engine g_engine;
struct SoundStruct{
ma_sound * sound;
};
static struct SoundStruct mystruct;
void create(void);
void play(void);
// create sound pointer and assign it to struct
void create(){
printf("\ncreating sound pointer\n");
ma_sound * pMaSound;
pMaSound = (ma_sound*) malloc(sizeof(*pMaSound));
if(pMaSound != NULL){
printf("OK\n");
}
mystruct.sound = pMaSound;
}
// init ma_sound with sound pointer in struct and play sound
void play(){
char* filePath = "/Users/user1/Downloads/asound.wav";
ma_data_source* ds = ma_sound_get_data_source(mystruct.sound);
if(ds == NULL){
ma_result result = ma_sound_init_from_file(&g_engine, filePath, 0, NULL, NULL, mystruct.sound);
if (result != MA_SUCCESS) {
printf("Failed to initialize sound \"%s\".", filePath);
}
}
ma_sound_seek_to_pcm_frame(mystruct.sound, 0);
ma_sound_start(mystruct.sound);
}
int main(int argc, char** argv)
{
ma_result result;
/* The engine needs to be initialized first. */
result = ma_engine_init(NULL, &g_engine);
if (result != MA_SUCCESS) {
printf("Failed to initialize audio engine.");
return -1;
}
printf("1. Press c to create then \n");
printf("2. Press p to play\n");
char c;
while( (c = getchar()) !='q' ){
printf("typed: %c",c);
if(c=='c'){
create();
}
if(c=='p'){
play();
}
}
return 0;
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Change |
Beta Was this translation helpful? Give feedback.
Change
malloc(sizeof(pMaSound))
tomalloc(sizeof(*pMaSound))
.