<commit_before>//
//  AudioSamplesContainer.swift
//  Waveform
//
//  Created by developer on 11/04/16.
//  Copyright © 2016 developer. All rights reserved.
//

import Foundation

protocol _AudioSamplesContainer {
    var buffer: UnsafePointer<Int16> { get }
    var numberOfChannels: Int { get }
    var samplesCount: Int { get }
    func sample(channelIndex channelIndex: Int, sampleIndex: Int) -> Int16
}

struct AudioSamplesContainer: _AudioSamplesContainer {
    let buffer: UnsafePointer<Int16>
    let samplesCount: Int
    let numberOfChannels: Int
    
    init(buffer: UnsafePointer<Int8>, length: Int, numberOfChannels: Int) {
        self.buffer           = UnsafePointer<Int16>(buffer)
        self.samplesCount     = length * sizeof(Int8)/sizeof(Int16) / numberOfChannels
        self.numberOfChannels = numberOfChannels
    }
    
    func sample(channelIndex channelIndex: Int, sampleIndex: Int) -> Int16 {
        assert(channelIndex < numberOfChannels)
        assert(sampleIndex < samplesCount)
        return buffer[numberOfChannels * sampleIndex + channelIndex]
    }
}<commit_msg>Refactoring. Make AudioSamplesContainer more generic.<commit_after>//
//  AudioSamplesContainer.swift
//  Waveform
//
//  Created by developer on 11/04/16.
//  Copyright © 2016 developer. All rights reserved.
//

import Foundation

protocol _AudioSamplesContainer {
    var buffer: UnsafePointer<Int16> { get }
    var numberOfChannels: Int { get }
    var samplesCount: Int { get }
    func sample(channelIndex channelIndex: Int, sampleIndex: Int) -> Int16
}

struct AudioSamplesContainer: _AudioSamplesContainer {
    let buffer: UnsafePointer<Int16>
    let samplesCount: Int
    let numberOfChannels: Int
    
    init<T>(buffer: UnsafePointer<T>, length: Int, numberOfChannels: Int) {
        self.buffer           = UnsafePointer<Int16>(buffer)
        self.samplesCount     = length * sizeof(T)/sizeof(Int16) / numberOfChannels
        self.numberOfChannels = numberOfChannels
    }
    
    func sample(channelIndex channelIndex: Int, sampleIndex: Int) -> Int16 {
        assert(channelIndex < numberOfChannels)
        assert(sampleIndex < samplesCount)
        return buffer[numberOfChannels * sampleIndex + channelIndex]
    }
}
{'fraction_non_alphanumeric': 0.09013833110218653, 'fraction_numerical': 0.020526550647032574, 'mean_word_length': 3.2704761904761903, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5212404', 'n_tokens_mistral': 675, 'n_tokens_neox': 632, 'n_words': 162}