Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

STUDY

gcc, play sound file, wave, mp3 본문

c

gcc, play sound file, wave, mp3

__main__ 2020. 6. 27. 18:28

Cygwin64 다운, 설치한 후에 gcc compiler를 설치하였다. 그 후에 샘플 wave 파일을 다운로드 받아서 플레이하려고 한다. [ StackOverflow: How to use PlaySound in C ]의 코드를 그대로 따라해봤는데, 에러 메시지가 잔뜩 출력될 뿐.

#include <stdio.h>
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>

int main(int argc, char *argv[])
{
  PlaySound("C:\Snakes and Ladders\snake.wav",NULL,SND_SYNC | SND_LOOP | SND_FILENAME);
  return 0;
}

 

에러 메시지를 보니 <mmsystem.h> 헤더와 관련이 있어, 헤더를 삭제하고 실행해보았다. 

#include <stdio.h>
#include <windows.h>
#include <windowsx.h>

int main(int argc, char *argv[]) {
  PlaySound(TEXT("dah.wav"), NULL, SND_FILENAME);
  return 0;
}

 

위 파일을 그냥 컴파일하면 안 되며, winmm.dll 이란 Windows audio API를 링크해주어야 한다. 

# command line
$ gcc morse.c -o morse.exe -lwinmm

 

CMD에서 직접 타이핑하지 않고, `CMakeLists.txt` 파일을 만들고 실행해볼 수도 있다. (Windows pro 64bits) 

cmake_minimum_required(VERSION 3.14.5)
project(gcc_morse)
add_executable(gcc_morse morse.c)
target_link_libraries(gcc_morse winmm)

 

 

dah.wav
0.10MB
dit.wav
0.07MB

'c' 카테고리의 다른 글

Read `wav` file  (0) 2020.07.15
Convert Big to Little Endian, vice versa  (0) 2020.07.06
Pointer to 2-D Character Array, Type Conversion  (0) 2020.04.02
raylib: GUI programming library  (0) 2020.02.18
MSYS2 `pacman -Syu` error  (0) 2020.02.18
Comments