<commit_before>/*
===========================================================================

daemon gpl source code
copyright (c) 2013 unvanquished developers

this file is part of the daemon gpl source code (daemon source code).

daemon source code is free software: you can redistribute it and/or modify
it under the terms of the gnu general public license as published by
the free software foundation, either version 3 of the license, or
(at your option) any later version.

daemon source code is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.  see the
gnu general public license for more details.

you should have received a copy of the gnu general public license
along with daemon source code.  if not, see <http://www.gnu.org/licenses/>.

===========================================================================
*/

#include "AudioPrivate.h"

namespace Audio {

    // Implementation of Sample

    Sample::Sample(std::string name): HandledResource<Sample>(this), refCount(0), name(std::move(name)) {
    }

    Sample::~Sample() {
    }

    void Sample::Use() {
    }

    AL::Buffer& Sample::GetBuffer() {
        return buffer;
    }

    void Sample::Retain() {
        refCount ++;
    }

    void Sample::Release() {
        refCount --;
    }

    int Sample::GetRefCount() {
        return refCount;
    }

    const std::string& Sample::GetName() {
        return name;
    }

    // Implementation of the sample storage

    static std::unordered_map<std::string, Sample*> samples;

    static Sample* errorSample = nullptr;
    bool initialized = false;

    void InitSamples() {
        if (initialized) {
            return;
        }
        //TODO make an error if it can't register
        //TODO use an aggressive sound instead to know we are missing something?
        errorSample = RegisterSample("sound/feedback/hit.wav");
        initialized = true;
    }

    void ShutdownSamples() {
        if (not initialized) {
            return;
        }

        for (auto it: samples) {
            delete it.second;
        }
        samples.clear();

        initialized = false;
    }

	std::vector<std::string> ListSamples() {
		if (not initialized) {
			return {};
		}

		std::vector<std::string> res;

		for (auto& it : samples) {
			res.push_back(it.first);
		}

		return res;<commit_msg>Audio: error out instead of crashing when the error sample cannot be loaded.<commit_after>/*
===========================================================================

daemon gpl source code
copyright (c) 2013 unvanquished developers

this file is part of the daemon gpl source code (daemon source code).

daemon source code is free software: you can redistribute it and/or modify
it under the terms of the gnu general public license as published by
the free software foundation, either version 3 of the license, or
(at your option) any later version.

daemon source code is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.  see the
gnu general public license for more details.

you should have received a copy of the gnu general public license
along with daemon source code.  if not, see <http://www.gnu.org/licenses/>.

===========================================================================
*/

#include "AudioPrivate.h"

namespace Audio {

    // Implementation of Sample

    Sample::Sample(std::string name): HandledResource<Sample>(this), refCount(0), name(std::move(name)) {
    }

    Sample::~Sample() {
    }

    void Sample::Use() {
    }

    AL::Buffer& Sample::GetBuffer() {
        return buffer;
    }

    void Sample::Retain() {
        refCount ++;
    }

    void Sample::Release() {
        refCount --;
    }

    int Sample::GetRefCount() {
        return refCount;
    }

    const std::string& Sample::GetName() {
        return name;
    }

    // Implementation of the sample storage

    static std::unordered_map<std::string, Sample*> samples;

    static const std::string errorSampleName = "sound/feedback/hit.wav";
    static Sample* errorSample = nullptr;
    bool initialized = false;

    void InitSamples() {
        if (initialized) {
            return;
        }
        //TODO use an aggressive sound instead to know we are missing something?
        errorSample = RegisterSample(errorSampleName);

        if (!errorSample) {
            Com_Error(ERR_FATAL, "Couldn't load the error sound sample '%s'", errorSampleName.c_str());
        }

        initialized = true;
    }

    void ShutdownSamples() {
        if (not initialized) {
            return;
        }

        for (auto it: samples) {
            delete it.second;
        }
        samples.clear();

        errorSample = nullptr;

        initialized = false;
    }

	std::vector<std::string> ListSamples() {
		if (not initialized) {
			return {};
		}

		std::vector<std::string> res;

		for (auto& it : samples) {
			res.push_back(it.first);
		}

		return res;
{'fraction_non_alphanumeric': 0.14967842525823427, 'fraction_numerical': 0.0023387253946599105, 'mean_word_length': 2.8644578313253013, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2856304', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1330, 'n_words': 490}