Loading prj_c_02_init...
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # this GNU-makefile relies on the GCC toolchain # nb: on Windows, the Mingw-w64 package provides the mingw32-make.exe command # ( see https://web.enib.fr/~harrouet/dev_tools/#windows.mingw )
#~~~~ control global settings ~~~~ # make opt=2 --> enable optimisation, then disable debug, but keep symbols # make opt=1 --> enable optimisation, then disable debug # make opt=0 --> disable optimisation, then enable debug opt=0 # make clang=1 --> use clang/clang++, not gcc/g++ # make clang=0 --> use gcc/g++, not clang/clang++ clang=0 # make wasm=1 --> target webassembly rather than the native platform # make wasm=0 --> target the native platform rather than webassembly wasm=0
#~~~~ build library or programs ~~~~ # if LIB_TARGET is provided, this library will be built (with its # platform-specific name), otherwise ${EXE_PREFIX}* programs will be built LIB_TARGET= EXE_PREFIX=prog
#~~~~ detect operating system ~~~~ ifneq (${OS},Windows_NT) ifneq (,${findstring Ubuntu,${shell lsb_release -i 2>/dev/null}}) OS:=Ubuntu else ifneq (,${findstring Raspbian,${shell lsb_release -i 2>/dev/null}}) # Standard distribution for Raspberry-Pi OS:=Raspbian else OS:=${strip ${shell uname -s}} endif ifneq (,${findstring Microsoft,${shell cat /proc/version 2>/dev/null}}) # Windows-Subsystem-for-Linux OS:=${OS}_WSL endif endif
#~~~~ adjust project-specific settings ~~~~ CPPFLAGS= # CPPFLAGS+=-I header/path LDFLAGS=-lm # LDFLAGS+=-L library/path -Wl,-rpath,library/path -l library_name CFLAGS= CXXFLAGS= BINFLAGS= ifneq (,${findstring Windows_NT,${OS}}) # nothing special for now else ifneq (,${strip ${LIB_TARGET}}) BINFLAGS+=-fPIC endif ifneq (,${findstring Darwin,${OS}}) # nothing special for now else ifneq (,${findstring Ubuntu,${OS}}) # sanitizer sometimes requires gold-linker on Ubuntu LDFLAGS+=-fuse-ld=gold else ifneq (,${findstring Raspbian,${OS}}) # some warnings may appear when mixing g++-6 and g++-7 on Raspbian CXXFLAGS+=-Wno-psabi else # nothing special for now endif endif endif
#~~~~ adjust platform-specific features (Posix/Windows/Emscripten...) ~~~~ ifneq (,${findstring Windows_NT,${OS}}) LIB_PREFIX= LIB_SUFFIX=.dll EXE_SUFFIX=.exe SKIP_LINE=echo. REMOVE=del /q else LIB_PREFIX=lib ifneq (,${findstring Darwin,${OS}}) LIB_SUFFIX=.dylib else LIB_SUFFIX=.so endif EXE_SUFFIX= SKIP_LINE=echo REMOVE=rm -rf endif ifeq (${strip ${wasm}},1) LIB_PREFIX:=lib LIB_SUFFIX:=.bc EXE_SUFFIX:=.html endif
#~~~~ deduce file names ~~~~ ifneq (,${strip ${LIB_TARGET}}) LIB_TARGET:=${LIB_PREFIX}${strip ${LIB_TARGET}}${LIB_SUFFIX} MAIN_C_FILES= MAIN_CXX_FILES= else LIB_TARGET:= MAIN_C_FILES=${wildcard ${strip ${EXE_PREFIX}}*.c} MAIN_CXX_FILES=${wildcard ${strip ${EXE_PREFIX}}*.cpp} endif COMMON_C_FILES=${filter-out ${MAIN_C_FILES},${wildcard *.c}} COMMON_CXX_FILES=${filter-out ${MAIN_CXX_FILES},${wildcard *.cpp}} # MAIN_OBJECT_FILES=${sort ${patsubst %.c,%.o,${MAIN_C_FILES}} \ ${patsubst %.cpp,%.o,${MAIN_CXX_FILES}}} COMMON_OBJECT_FILES=${sort ${patsubst %.c,%.o,${COMMON_C_FILES}} \ ${patsubst %.cpp,%.o,${COMMON_CXX_FILES}}} OBJECT_FILES=${MAIN_OBJECT_FILES} ${COMMON_OBJECT_FILES} DEPEND_FILES=${patsubst %.o,%.d,${OBJECT_FILES}} EXE_FILES=${sort ${patsubst %.c,%${EXE_SUFFIX},${MAIN_C_FILES}} \ ${patsubst %.cpp,%${EXE_SUFFIX},${MAIN_CXX_FILES}}} # GENERATED_FILES=${DEPEND_FILES} ${OBJECT_FILES} ${LIB_TARGET} ${EXE_FILES} ifneq (,${findstring Darwin,${OS}}) GENERATED_FILES+=${wildcard *.dSYM} endif ifeq (${strip ${wasm}},1) GENERATED_FILES+=${patsubst %.html,%.js,${EXE_FILES}} GENERATED_FILES+=${patsubst %.html,%.html.mem,${EXE_FILES}} GENERATED_FILES+=${patsubst %.html,%.wasm,${EXE_FILES}} GENERATED_FILES+=${patsubst %.html,%.wast,${EXE_FILES}} endif GENERATED_FILES+=${wildcard output_* *~}
#~~~~ compiler/linker settings ~~~~ CPPFLAGS+=-MMD -pedantic -Wall -Wextra -Wconversion -Wno-sign-conversion CPPFLAGS+=-Wno-unused -Wno-unused-parameter CPPFLAGS+=-Werror -Wfatal-errors CFLAGS+=-std=c99 -Wc++-compat -Wwrite-strings -Wold-style-definition -Wvla CXXFLAGS+=-std=c++17 -Wno-missing-braces LDFLAGS+= BINFLAGS+= ifeq (${strip ${wasm}},1) CC=emcc CXX=em++ CPPFLAGS+=-Wno-dollar-in-identifier-extension LDFLAGS+=-s ALLOW_MEMORY_GROWTH=1 else ifeq (${strip ${clang}},1) CC=clang CXX=clang++ else CC=gcc CXX=g++ endif # ifneq (,${strip ${MAIN_CXX_FILES} ${COMMON_CXX_FILES}}) # force c++ link if there is at least one c++ source file LD:=${CXX} else LD:=${CC} endif
#~~~~ debug/optimisation settings ~~~~ ifneq (${strip ${opt}},0) CPPFLAGS+=-DNDEBUG BINFLAGS+=-O3 -ffast-math # BINFLAGS+=-fopt-info-vec-optimized ifneq (${strip ${wasm}},1) BINFLAGS+=-march=native endif ifeq (${strip ${opt}},2) # optimise but keep symbols for profiling BINFLAGS+=-g -fno-omit-frame-pointer else BINFLAGS+=-fomit-frame-pointer endif else CPPFLAGS+=-UNDEBUG BINFLAGS+=-g -O0 ifeq (${strip ${wasm}},1) # sanitizer is not available yet with Emscripten else ifneq (,${findstring Windows_NT,${OS}}) # sanitizer is not available yet on Windows else BINFLAGS+=-fsanitize=address,undefined ifneq (,${findstring Raspbian,${OS}}) # dynamic sanitizer libraries may not be found on Raspbian BINFLAGS+=-static-libasan -static-libubsan endif endif endif
#~~~~ main target ~~~~ all : ${EXE_FILES} ${LIB_TARGET}
rebuild : clean all
.SUFFIXES: .SECONDARY: .PHONY: all clean rebuild
#~~~~ linker command to produce the library (if any) ~~~~ ${LIB_TARGET} : ${COMMON_OBJECT_FILES} @echo ==== linking [opt=${opt}] $@ ==== ${LD} -shared -o $@ $^ ${BINFLAGS} ${LDFLAGS} @${SKIP_LINE}
#~~~~ linker command to produce the executable files (if any) ~~~~ %${EXE_SUFFIX} : %.o ${COMMON_OBJECT_FILES} @echo ==== linking [opt=${opt}] $@ ==== ${LD} -o $@ $^ ${BINFLAGS} ${LDFLAGS} @${SKIP_LINE}
#~~~~ compiler command for every source file ~~~~ %.o : %.c @echo ==== compiling [opt=${opt}] $< ==== ${CC} -o $@ $< -c ${BINFLAGS} ${CPPFLAGS} ${CFLAGS} @${SKIP_LINE}
%.o : %.cpp @echo ==== compiling [opt=${opt}] $< ==== ${CXX} -o $@ $< -c ${BINFLAGS} ${CPPFLAGS} ${CXXFLAGS} @${SKIP_LINE}
-include ${DEPEND_FILES}
#~~~~ remove generated files ~~~~ clean : @echo ==== cleaning ==== ${REMOVE} ${GENERATED_FILES} @${SKIP_LINE}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
before the loop counter=0 counter=1 counter=2 counter=3 counter=4 after the loop
#define SAMPLE_COUNT 18
before the loop counter=0 time=0 counter=1 time=0.222222 counter=2 time=0.444444 counter=3 time=0.666667 counter=4 time=0.888889 counter=5 time=1.11111 counter=6 time=1.33333 counter=7 time=1.55556 counter=8 time=1.77778 counter=9 time=2 counter=10 time=2.22222 counter=11 time=2.44444 counter=12 time=2.66667 counter=13 time=2.88889 counter=14 time=3.11111 counter=15 time=3.33333 counter=16 time=3.55556 counter=17 time=3.77778 after the loop
#include <math.h>en haut de votre fichier de code source✍
#include <stdio.h>qui donne accès aux fonctionnalités d'affichage.
before the loop counter=0 time=0 signal=0 counter=1 time=0.222222 signal=0.984808 counter=2 time=0.444444 signal=0.34202 counter=3 time=0.666667 signal=-0.866025 counter=4 time=0.888889 signal=-0.642788 counter=5 time=1.11111 signal=0.642788 counter=6 time=1.33333 signal=0.866025 counter=7 time=1.55556 signal=-0.34202 counter=8 time=1.77778 signal=-0.984808 counter=9 time=2 signal=-4.89859e-16 counter=10 time=2.22222 signal=0.984808 counter=11 time=2.44444 signal=0.34202 counter=12 time=2.66667 signal=-0.866025 counter=13 time=2.88889 signal=-0.642788 counter=14 time=3.11111 signal=0.642788 counter=15 time=3.33333 signal=0.866025 counter=16 time=3.55556 signal=-0.34202 counter=17 time=3.77778 signal=-0.984808 after the loop
initialising samples... displaying samples... samples[0]=0 samples[1]=0.984808 samples[2]=0.34202 samples[3]=-0.866025 samples[4]=-0.642788 samples[5]=0.642788 samples[6]=0.866025 samples[7]=-0.34202 samples[8]=-0.984808 samples[9]=-4.89859e-16 samples[10]=0.984808 samples[11]=0.34202 samples[12]=-0.866025 samples[13]=-0.642788 samples[14]=0.642788 samples[15]=0.866025 samples[16]=-0.34202 samples[17]=-0.984808
#!/usr/bin/env python # -*- coding: utf-8 -*- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import sys import os import struct
def txt(fmt, *args, **kw): return fmt.format(*args, **kw)
def out(fmt, *args, **kw): sys.stdout.write(txt(fmt, *args, **kw))
def err(fmt, *args, **kw): sys.stderr.write(txt(fmt, *args, **kw))
if len(sys.argv)!=2: err('usage: {} sample_file\n', sys.argv[0]) sys.exit(1)
input_name=sys.argv[1] output_name=txt('{}.wav', os.path.splitext(input_name)[0])
words=iter(word for line in open(input_name, 'r') for word in line.strip().split())
try: sample_rate=float(next(words)) except: err('sample_rate expected\n') sys.exit(1) out('sample_rate: {}\n', sample_rate)
try: sample_count=int(next(words)) except: err('sample_count expected\n') sys.exit(1) out('sample_count: {}\n', sample_count)
try: samples=[float(next(words)) for i in range(sample_count)] except: err('{} samples expected\n', sample_count) sys.exit(1)
sample_size=2 # 16 bits channel_count=1 # monophonic size=channel_count*sample_count*sample_size chunk_size=36+size bits_per_sample=8*sample_size byte_rate=sample_rate*channel_count*bits_per_sample/8.0 output=open(output_name, 'wb') output.write(b'RIFF'+ struct.pack('<I', chunk_size)+ b'WAVE'+ b'fmt '+ struct.pack('<I', 16)+ # subchunk1size struct.pack('<H', 1)+ # pcm struct.pack('<H', channel_count)+ struct.pack('<I', int(sample_rate))+ struct.pack('<I', int(byte_rate))+ struct.pack('<H', 4)+ # block-align struct.pack('<H', bits_per_sample)+ b'data'+ struct.pack('<I', size)) i16_max=(1<<15)-1 for s in samples: clamped=max(-1.0, min(1.0, s)) output.write(struct.pack('<h', int(clamped*i16_max))) out('{} translated to {}\n', input_name, output_name)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44100 176400 0 0.0313242 0.0625253 0.0934807 0.124069 0.15417 ... de très nombreuses autres valeurs ... -0.183665 -0.15417 -0.124069 -0.0934807 -0.0625253 -0.0313242
./prog_intro >output_sound.samples
python samples_to_wav.py output_sound.samples
<math.h>est nécessaire. Il ne reste plus qu'à intervenir sur le programme principal pour remplacer la formule explicite renseignant la variable signal par un appel à la fonction sine_wave().
"waves.h"est nécessaire.
<math.h>. Déclarez et définissez une fonction sawtooth_wave() ayant le même prototype que la fonction sine_wave().