Update C sources, add new functions and rename package to
This commit is contained in:
parent
391c25482d
commit
08aa518a46
156 changed files with 34542 additions and 19573 deletions
|
@ -12,34 +12,34 @@ const (
|
|||
)
|
||||
|
||||
func main() {
|
||||
raylib.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
||||
rl.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
||||
|
||||
raylib.InitAudioDevice()
|
||||
rl.InitAudioDevice()
|
||||
|
||||
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||
stream := raylib.InitAudioStream(22050, 32, 1)
|
||||
stream := rl.InitAudioStream(22050, 32, 1)
|
||||
|
||||
//// Fill audio stream with some samples (sine wave)
|
||||
data := make([]float32, maxSamples)
|
||||
|
||||
for i := 0; i < maxSamples; i++ {
|
||||
data[i] = float32(math.Sin(float64((2*raylib.Pi*float32(i))/2) * raylib.Deg2rad))
|
||||
data[i] = float32(math.Sin(float64((2*rl.Pi*float32(i))/2) * rl.Deg2rad))
|
||||
}
|
||||
|
||||
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||
// for that reason, there is a clip everytime audio stream is looped
|
||||
raylib.PlayAudioStream(stream)
|
||||
rl.PlayAudioStream(stream)
|
||||
|
||||
totalSamples := int32(maxSamples)
|
||||
samplesLeft := int32(totalSamples)
|
||||
|
||||
position := raylib.NewVector2(0, 0)
|
||||
position := rl.NewVector2(0, 0)
|
||||
|
||||
raylib.SetTargetFPS(30)
|
||||
rl.SetTargetFPS(30)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
// Refill audio stream if required
|
||||
if raylib.IsAudioBufferProcessed(stream) {
|
||||
if rl.IsAudioBufferProcessed(stream) {
|
||||
numSamples := int32(0)
|
||||
if samplesLeft >= maxSamplesPerUpdate {
|
||||
numSamples = maxSamplesPerUpdate
|
||||
|
@ -47,7 +47,7 @@ func main() {
|
|||
numSamples = samplesLeft
|
||||
}
|
||||
|
||||
raylib.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||
rl.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||
|
||||
samplesLeft -= numSamples
|
||||
|
||||
|
@ -57,25 +57,25 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, raylib.LightGray)
|
||||
rl.ClearBackground(rl.RayWhite)
|
||||
rl.DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, rl.LightGray)
|
||||
|
||||
// NOTE: Draw a part of the sine wave (only screen width)
|
||||
for i := 0; i < int(raylib.GetScreenWidth()); i++ {
|
||||
for i := 0; i < int(rl.GetScreenWidth()); i++ {
|
||||
position.X = float32(i)
|
||||
position.Y = 250 + 50*data[i]
|
||||
|
||||
raylib.DrawPixelV(position, raylib.Red)
|
||||
rl.DrawPixelV(position, rl.Red)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||
rl.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||
|
||||
raylib.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue