Moscardo69
Moscardo69

Reputation: 1

Troubles with implementing retroactive audio recording (save last X min instead of whole recoding) functionality to audio recording app Android Studio

Using TVAC Studio's tutorial, I built an app that records audio and saves the files in a list which can be played back within the app.

My problem is that I want to continuously record and upon repressing the mic button, save the last X minutes instead of the whole recoding. I tried to implement a circular/ring buffer, I have not been successful being left with countless errors and cannot seem to get anywhere so I am back to square one. Project can be accessed here and the buffer code I have made a start with is below:

drive: https://drive.google.com/drive/folders/1zHz70clC2hYrSUekjYf9ybZV2jDxLsRM?usp=sharing

//Write

    void API_WriteToBuffer(int data_element)
    {
        if(Is_BufferFull())
        {
            printf("\nBuffer is Full");
        }
        else
        {
            circularBuffer[Head] = data_element;
            printf("\nAPI_WriteToBuffer: %d", circularBuffer[Head]);
            Head = Head + 1 % BUFFER_SIZE;
            if(Head == Tail){
                IsFull_Flag =1;
            }
        }
    }

//Read

    void API_ReadFromBuffer(int * data_element)
    (
            if(Is_BufferEmpty())
    {
        printf("\nBuffer is Empty");
        )
        else
        {
            *data_element = circularBuffer[Tail];
            printf(".\nAPI_ReadFromBuffer: %d"), CircularBuffer[Tail]);
            Tail = (Tail + 1) % BUFFER_SIZE;
            IsFull_Flag = 0;
        }

    }
            )

    int Is_BufferFull(void)
    {
        return(IsFull_Flag);
    }

    int Is_BufferEmpty(void)
    {
        int temp = 0;
        if((Head == Tail) &&
                (IsFull_Flag !=1))
        {
            temp = 1;
        }
        return(temp);
    }

Upvotes: 0

Views: 83

Answers (0)

Related Questions