Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rok

Pages: [1]
1
Audio / Re: SoundStream Timing
« on: May 22, 2015, 07:07:42 pm »

Solved it that way somehow. Going to try how it works when I do all the FFT and convolution inside it  :D

2
Audio / Re: SoundStream Timing
« on: May 22, 2015, 06:19:41 pm »
But how should I change the data inside the function itself (in a for loop)? I just don't get it. ???


protected override bool OnGetData(out short[] samples) {
    short[] smallBuffer = new short[4410];
    // FOR LOOP HERE
    samples = smallBuffer;
    return true;
}
 

Could I get some short example or concept?



Here's how I changed it now but that does still not work.

public MyStream()
        {
            buffer = new SoundBuffer("C:/Users/Rok/Desktop/Reverbi/Sampli/chill2.wav");

            sound_left = new short[buffer.Samples.Length / 2];

            sound_right = new short[buffer.Samples.Length / 2];

            Split(buffer.Samples, sound_left, sound_right);

            Initialize(1, 44100);

        }

        protected override bool OnGetData(out short[] samples)
        {
            short[] smallBuffer = new short[4410];

            for (int i = 0; i < sound_left.Length - 4410; i += 4410)
            {
                if (i > sound_left.Length - 8820)
                {
                    i = 1;
                }

                for (int l = 0; l < 4410; l++)
                {
                    smallBuffer[l] = sound_left[i + l];
                }

                Console.WriteLine(i);

                //SetSample(smallBuffer);

                Console.WriteLine("["+i+"] Offset: " + PlayingOffset.AsSeconds());
            }

            samples = smallBuffer;

            return true;
        }
 

3
Audio / SoundStream Timing
« on: May 22, 2015, 05:17:27 pm »
I want to use SoundStream to play the data I'm giving to it. The audio in this example is loaded from a normal buffer so I get the basics before moving on. I'm timing the swapping of data with Thread.Sleep but I guess it's not the right way to do it. There's some overlapping happening while playing.

Without the "correct" amount of Thread.Sleep the sound is even worse.

1. How should I do the timing of swapping the data so the playback will be as smooth as possible?

2. It's not possible to somehow append the data instead of overwriting right?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFML.Audio;
using System.Threading;
 
namespace Stream
{
 
    class MyStream : SoundStream
    {
 
        short[] current_samples;
        public MyStream()
        {
            Initialize(1, 44100);
        }
 
        protected override bool OnGetData(out short[] samples)
        {
            samples = current_samples;
            return true;
        }
 
        protected override void OnSeek(SFML.System.Time timeOffset)
        {
            Console.WriteLine(timeOffset);
        }
 
        public void Split(short[] samples, short[] left, short[] right)
        {
            int c = 0;
            for (int i = 0; i < samples.Length - 1; i += 2)
            {
                left[c] = samples[i];
                right[c] = samples[i + 1];
                c++;
            }
        }
 
        public void SetSample(short[] novi)
        {
            current_samples = novi;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            SoundBuffer buffer = new SoundBuffer("some_music.wav");
 
            short[] sound_left = new short[buffer.Samples.Length / 2];
 
            short[] sound_right = new short[buffer.Samples.Length / 2];
 
            MyStream s = new MyStream();
 
            s.Split(buffer.Samples, sound_left, sound_right);
 
            short[] smallBuffer = new short[4410];
 
            for (int i = 0; i < sound_left.Length - 4410; i += 4410)
            {
                for (int l = 0; l < 4410; l++)
                {
                    smallBuffer[l] = sound_left[i + l];
                }
 
                s.SetSample(smallBuffer);
               
                if (i == 0)
                {
                    s.Play();
                }
 
                Thread.Sleep(100);
            }
        }
    }
}
 

Pages: [1]